From f7ad9472ffc0a6866cf229c05920a6d7f300a89b Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Tue, 5 Mar 2024 19:08:30 +0300 Subject: [PATCH] add /shipment/add --- erp24/actions/shipment/AddAction.php | 27 ++++- erp24/controllers/ShipmentController.php | 8 +- erp24/inc/uni2.php | 63 ++++++----- erp24/modul/shipment/add.php | 5 +- erp24/records/StoreOrders.php | 23 +++- erp24/views/shipment/add.php | 132 +++++++++++++++++++++++ 6 files changed, 221 insertions(+), 37 deletions(-) create mode 100644 erp24/views/shipment/add.php diff --git a/erp24/actions/shipment/AddAction.php b/erp24/actions/shipment/AddAction.php index 784a75c..7dbf9c0 100644 --- a/erp24/actions/shipment/AddAction.php +++ b/erp24/actions/shipment/AddAction.php @@ -2,11 +2,34 @@ namespace yii_app\actions\shipment; +use Yii; use yii\base\Action; +use yii\helpers\ArrayHelper; +use yii_app\records\ShipmentProviders; +use yii_app\records\StoreOrders; +use yii_app\records\UniversalCatalogItem; class AddAction extends Action { - public function run() { - return $this->controller->render('add'); + public function run($id) { + $model = StoreOrders::find()->where(['id' => $id])->one(); + /** @var $model StoreOrders */ + + if (Yii::$app->request->isPost && $model->load(Yii::$app->request->post())) { + $model->setProviders(); + if ($model->validate()) { + $model->save(); + } + } + + $cities = ArrayHelper::map(UniversalCatalogItem::find() + ->where(['catalog_alias' => 'cities']) + ->orderBy(['name' => SORT_ASC])->all(),'id', 'name'); + $statuses = ArrayHelper::map(UniversalCatalogItem::find() + ->where(['catalog_alias' => 'shipment']) + ->orderBy(['name' => SORT_ASC])->all(),'guid', 'name'); + $providers = ArrayHelper::map(ShipmentProviders::find()->all(),'id', 'name'); + return $this->controller->render('add', + compact('model', 'cities', 'statuses', 'providers')); } } \ No newline at end of file diff --git a/erp24/controllers/ShipmentController.php b/erp24/controllers/ShipmentController.php index 182cbbb..1419c53 100644 --- a/erp24/controllers/ShipmentController.php +++ b/erp24/controllers/ShipmentController.php @@ -6,7 +6,11 @@ use yii\web\Controller; class ShipmentController extends Controller { - public function actionIndex() { - return $this->render('index'); + public function actions() { + return [ + 'add' => \yii_app\actions\shipment\AddAction::class, + ]; } + + public function actionIndex() { return $this->render('index'); } } \ No newline at end of file diff --git a/erp24/inc/uni2.php b/erp24/inc/uni2.php index 2bcdd04..34fc1e2 100644 --- a/erp24/inc/uni2.php +++ b/erp24/inc/uni2.php @@ -1,4 +1,7 @@ -array("name"=>"Сделки/заказы", "table"=>"orders_amo"), "client"=>array("name"=>"Клиент", "table"=>"contacts","type_id"=>0), @@ -175,7 +178,7 @@ $r .=' .dd-handle, .dd-content {display: block; margin: 0px 0;padding: 1px 0px; } */ $fields_table_edit =" -
+
$r
@@ -221,7 +224,7 @@ $r .=' '; // //
$r
$fields_edit =" - +
$r
@@ -278,7 +281,7 @@ if(!empty($act)) $action .="$act/"; - unif_fields_show($forma, $table_sql) ; + unif_fields_show($forma, $table_sql) ; $idname=$forma["id"]["name"]; @@ -453,7 +456,7 @@ $form_field_uni[$row["name_eng"]]=$arr_2; } -construct_form_submit_uni($forma, $table_sql,$modul_uni,$form_field_hide_array); +construct_form_submit_uni($forma, $table_sql,$modul_uni,$form_field_hide_array); ///////// @@ -599,7 +602,7 @@ $p=0; $sql=""; $param2=array(); $param2['id2']=$id; -foreach($sql_upvalue as $nm => $vl) { +foreach($sql_upvalue ?? [] as $nm => $vl) { if($p>0) $sql .=","; $sql .=" `$nm` = :$nm"; $param2[$nm]=$vl; @@ -807,14 +810,14 @@ elseif(empty($forma[$name]["mysql_table"])) { $sql1 .=",$name"; $sql2 .=", '$va $val=''; if($name!="save" and $name!="id" and $forma[$name]["type"]!="image" and $forma[$name]["type"]!="table" and $forma[$name]["type"]!="video" and $forma[$name]["type"]!="file" and !isset($forma[$name]["no_form"]) and $forma[$name]["type"]!="html") { -if(isset($_POST[$name])) { -$val=htmlentities($_POST[$name]); +if(isset($_POST[$name])) { +$val= htmlentities(is_array($_POST[$name]) ? $_POST[$name][0] : $_POST[$name]); //echo"
$name value=$val "; if($forma[$name]["tip"]=="array") { -$val=implode(",",htmlentities($_POST[$name])); -$massiv=[]; +$val=implode(",",$_POST[$name]); +$massiv=[]; if($forma[$name]["type"]=="radio" or $forma[$name]["type"]=="html") { foreach($_POST[$name] as $key6 => $valon) { if($valon=="on") $massiv[]=$key6; @@ -1206,7 +1209,8 @@ if(!empty($mess)) mess($mess); echo"
-"; +"; +echo "request->getCsrfToken() . "\" />"; // @@ -1216,7 +1220,7 @@ if(!empty($group_menu)) { $group=get_sql_array("uni_status", "id", "name", " WHERE type='".$modul."_group' order by posit DESC"); $i=0; $group_menu ='
'; -foreach($group as $gr_id => $nameg){ +foreach($group ?? [] as $gr_id => $nameg){ if($i==0) { $script="все Основные "; $script2="$('.f_0').show();"; } else { $script=""; $script2=""; } @@ -1233,7 +1237,7 @@ echo $group_menu; if(!empty($forma["save"])) {$save=$forma["save"]; unset($forma["save"]); } -foreach($form_field_uni as $name => $pole_arr2) { +foreach($form_field_uni ?? [] as $name => $pole_arr2) { $forma[$name]=$pole_arr2; //echo" +++++ {$name} {$pole_arr2["value"]} "; } @@ -1767,12 +1771,12 @@ optgroup[label] { } -/*end optgroup*/ - - - - - +/*end optgroup*/ + + + + + /*multy-select*/ if($pole_arr["type"]=="multiple") { $item[$name]=explode(",",$item[$name]); @@ -1796,16 +1800,16 @@ echo" id=crm$name>"; if(!empty($forma[$name]["val_arr"])) { foreach($forma[$name]["val_arr"] as $vid =>$namev) { echo""; } -} +} echo"
"; } -/*end multy-select*/ - - +/*end multy-select*/ + + /*radio*/ @@ -2241,9 +2245,9 @@ return $item; function construct_modul_form_azea($modul) { -global $modul,$db,$h1,$group_menu,$uni_fields, $_CONFIG,$forma_sql_table; +global /*$modul,*/$db,$h1,$group_menu,$uni_fields, $_CONFIG,$forma_sql_table; $data=$db::getRows("SELECT * FROM modules_uni_fields WHERE modul=? ORDER BY posit DESC",[$modul]); -foreach ($data as $row) { +foreach ($data as $row) { $image_config=json_decode($row["image_config"], true,JSON_UNESCAPED_UNICODE); $ext_1=explode(",",$image_config["ext"]); @@ -2265,7 +2269,7 @@ if(!empty($uni_fields)) $uni_fields=$modul; -construct_form_azea($forma,$modul,$h1,"2",$uni_fields); +construct_form_azea($forma,$modul,$h1,"2",$uni_fields); if(!empty($_CONFIG["bottom_content"])) echo $_CONFIG["bottom_content"]; @@ -2792,6 +2796,9 @@ $spiski_arr=array( ); +if (!isset($zz)) { + $zz = ""; +} $zz=preg_replace_callback("|{RAND}|","generate_r", $zz); $zz=str_replace('[YEAR]',date("Y",time()),$zz); $zz=str_replace('[MONTH]',date("m",time()),$zz); diff --git a/erp24/modul/shipment/add.php b/erp24/modul/shipment/add.php index ee12162..55682af 100644 --- a/erp24/modul/shipment/add.php +++ b/erp24/modul/shipment/add.php @@ -7,6 +7,9 @@ include_once("inc/uni.php"); include_once("inc/uni2.php"); global $h1,$group_menu,$uni_fields, $forma_sql_table; + +error_reporting(E_ALL ^ E_NOTICE); + $h1="Добавить "; $group_menu=0; $uni_fields=0; $modul="shipment"; $forma_sql_table="store_orders"; @@ -25,7 +28,7 @@ $_SESSION["default"][$modul]["cat_id"]=$catid; include"templates/top.php"; -construct_modul_form_azea($modul); +construct_modul_form_azea($modul); diff --git a/erp24/records/StoreOrders.php b/erp24/records/StoreOrders.php index 17c996f..746f90d 100755 --- a/erp24/records/StoreOrders.php +++ b/erp24/records/StoreOrders.php @@ -16,7 +16,7 @@ use Yii; * @property string $division_date дата деления * @property int $division_hours * @property string $delivery_date_fact Дата прихода товара на склад - * @property int $price_logistic + * @ property int $price_logistic * @property string $comments * @property int $admin_id * @property string $date_add @@ -25,9 +25,12 @@ use Yii; * @property string $status_logi * @property string $date_update Дата и врепмя обновления информации в таблице храннеия data * @property string $update_html HTML блок расчета по формулам + * @property int city_id */ class StoreOrders extends \yii\db\ActiveRecord { + public $providers; + /** * {@inheritdoc} */ @@ -42,9 +45,9 @@ class StoreOrders extends \yii\db\ActiveRecord public function rules() { return [ - [['name', 'parent_id', 'date_start', 'date_end', 'delivery_date', 'division_date', 'division_hours', 'delivery_date_fact', 'price_logistic', 'comments', 'admin_id', 'date_add', 'providers_arr', 'status_logi', 'date_update', 'update_html'], 'required'], - [['parent_id', 'division_hours', 'price_logistic', 'admin_id', 'status'], 'integer'], - [['date_start', 'date_end', 'delivery_date', 'division_date', 'delivery_date_fact', 'date_add', 'date_update'], 'safe'], + [['name', 'parent_id', 'date_start', 'date_end', 'delivery_date', 'division_date', 'division_hours', 'delivery_date_fact', /*'price_logistic',*/ 'comments', 'admin_id', 'date_add', 'providers_arr', 'status_logi', 'date_update', 'update_html'], 'required'], + [['parent_id', 'division_hours', /*'price_logistic',*/ 'admin_id', 'status'], 'integer'], + [['date_start', 'date_end', 'delivery_date', 'division_date', 'delivery_date_fact', 'date_add', 'date_update', 'city_id', 'providers'], 'safe'], [['comments', 'status_logi', 'update_html'], 'string'], [['name', 'providers_arr'], 'string', 'max' => 255], ]; @@ -76,4 +79,16 @@ class StoreOrders extends \yii\db\ActiveRecord 'update_html' => 'Update Html', ]; } + + public function getCity() { + return $this->hasOne(CityStore::class, ['id' => 'city_id']); + } + + public function getProviders() { + return explode(',', $this->providers_arr); + } + + public function setProviders() { + $this->providers_arr = implode(',', $this->providers); + } } diff --git a/erp24/views/shipment/add.php b/erp24/views/shipment/add.php new file mode 100644 index 0000000..eb91af1 --- /dev/null +++ b/erp24/views/shipment/add.php @@ -0,0 +1,132 @@ + + +
+

'btn btn-primary btn-sm']) ?> name ?>

+ + + + field($model, 'city_id')->widget(Select2::class, [ + 'data' => $cities, + 'language' => 'ru', + 'options' => ['placeholder' => 'Город...'], + 'pluginOptions' => [ + 'allowClear' => true, + ] + ])->label(false)) ?> + +
Устанавливайте город - к городу привязываются магазины. Статистика будет считаться ТОЛЬКО по тем магазинам которые назначены городу. Выбрали МСК - значит стастистика продаж и списаний будет считатся только по 2-м магазинам (на 31 января 24 г)
+ + field($model, 'name')->textInput()->label(false));?> + + field($model, 'status')->widget(Select2::class, [ + 'data' => $statuses, + 'language' => 'ru', + 'options' => ['placeholder' => 'Статус...'], + 'pluginOptions' => [ + 'allowClear' => true, + ] + ])->label(false)) ?> + + field($model, 'date_start')->widget(DateTimePicker::class, [ + 'language' => 'ru', + 'template' => '{input}', + 'clientOptions' => [ + 'autoclose' => true, + 'format' => 'Y-m-d', + 'todayBtn' => true + ], + ])->label(false));?> + +
Не может быть больше текущего дня! От этой даты в назад прошлое считаем статистику для автозаказа - 7 дней. Продажи, средние продажи за 4 недели, списания. Внимательно устанавливайте дату - как правило это понедельник этой недели
+ + field($model, 'division_date')->widget(DateTimePicker::class, [ + 'language' => 'ru', + 'template' => '{input}', + 'clientOptions' => [ + 'autoclose' => true, + 'format' => 'Y-m-d', + 'todayBtn' => true + ], + ])->label(false));?> + +
Дата деления участвует в фильтре выборки данных для расчета авто-деления по магазинам. Данные для деления основываются на этой ячейке и должны расчитываться либо в дату деления либо после. В статусе деление по магазинам не должно быть такого чтобы дата деления бала в будущем от текущей даты. От этой даты назад в прошлое расчитываются актуальные продажи и списания.
+ + field($model, 'providers')->widget(Select2::class, [ + 'data' => $providers, + 'language' => 'ru', + 'options' => ['placeholder' => 'Статус...'], + 'pluginOptions' => [ + 'allowClear' => true, + 'multiple' => true, + ] + ])->label(false)) ?> + + field($model, 'delivery_date_fact')->widget(DateTimePicker::class, [ + 'language' => 'ru', + 'template' => '{input}', + 'clientOptions' => [ + 'autoclose' => true, + 'format' => 'Y-m-d', + 'todayBtn' => true + ], + ])->label(false));?> + + field($model, 'parent_id')->textInput()->label(false));?> + + field($model, 'delivery_date')->widget(DateTimePicker::class, [ + 'language' => 'ru', + 'template' => '{input}', + 'clientOptions' => [ + 'autoclose' => true, + 'format' => 'Y-m-d', + 'todayBtn' => true + ], + ])->label(false));?> + +
Информационная ячейка не влияет на статистику - дата ориентировочной (примерной) доставки в будущем
+ + field($model, 'date_add')->widget(DateTimePicker::class, [ + 'language' => 'ru', + 'template' => '{input}', + 'clientOptions' => [ + 'autoclose' => true, + 'format' => 'Y-m-d', + 'todayBtn' => true + ], + ])->label(false));?> + +
Информационная ячейка влияет на сортировку в общем списке закупок. Не участвует в формулах расчета данных для автозаказа.
+ + field($model, 'comments')->textarea(['rows' => 6])->label(false));?> + + field($model, 'course_dollar')->textInput()->label(false));?> + + field($model, 'course_euro')->textInput()->label(false));?> + + field($model, 'related_order_id')->textInput()->label(false));?> + +
+ 'btn btn-success btn-lg'])?> +
+ + +
+ -- 2.39.5