From 11f46f0cc48c9886a56f031746b980e7a5fc0bd6 Mon Sep 17 00:00:00 2001 From: "leon.mbs@gmail.com" Date: Wed, 20 Dec 2023 15:04:58 +0200 Subject: [PATCH 01/13] horoshop draft --- www/app/modules/hr/helper.php | 222 ++++++++++++++ www/app/modules/hr/items.php | 426 ++++++++++++++++++++++++++ www/app/modules/hr/options.php | 80 +++++ www/app/modules/hr/orders.php | 279 +++++++++++++++++ www/app/pages/base.php | 6 +- www/app/pages/options.php | 6 +- www/app/pages/roles.php | 7 + www/app/system.php | 2 +- www/templates/modules/hr/items.html | 132 ++++++++ www/templates/modules/hr/options.html | 68 ++++ www/templates/modules/hr/orders.html | 121 ++++++++ www/templates/pages/base.html | 35 +++ www/templates/pages/options.html | 5 + www/templates/pages/roles.html | 10 + 14 files changed, 1394 insertions(+), 5 deletions(-) create mode 100644 www/app/modules/hr/helper.php create mode 100644 www/app/modules/hr/items.php create mode 100644 www/app/modules/hr/options.php create mode 100644 www/app/modules/hr/orders.php create mode 100644 www/templates/modules/hr/items.html create mode 100644 www/templates/modules/hr/options.html create mode 100644 www/templates/modules/hr/orders.html diff --git a/www/app/modules/hr/helper.php b/www/app/modules/hr/helper.php new file mode 100644 index 000000000..cc616d256 --- /dev/null +++ b/www/app/modules/hr/helper.php @@ -0,0 +1,222 @@ +getMessage()); + return; + } + + if(!is_array($ret)) { + //System::setSuccessMsg("Успішне з`єднання"); + return; + } + + $list = array(); + foreach($ret['order_status_options'] as $st) { + $list[$st['name']]=$st['title'] ; + } + + return $list; + + } + + public static function make_request($method, $url, $body='') { + + $modules = System::getOptions("modules"); + $usessl = $modules['pussl']; + + + $headers = array( + 'Authorization: Bearer ' . $modules['puapitoken'], + 'Content-Type: application/json' + ); + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, 'https://my.prom.ua' . $url); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + + if (strtoupper($method) == 'POST') { + curl_setopt($ch, CURLOPT_POST, true); + } + + if (strlen($body)>0) { + curl_setopt($ch, CURLOPT_POSTFIELDS, $body); + } + + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $usessl == 1); + // \App\Helper::log(json_encode($body, JSON_UNESCAPED_UNICODE)) ; + $result = curl_exec($ch); + if (curl_errno($ch) > 0) { + throw new \Exception(curl_error($ch)); + } + $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + if($httpcode >=300) { + throw new \Exception("http code ".$httpcode); + } + curl_close($ch); + + $ret = json_decode($result, true) ; + if (strlen($ret['error']) > 0) { + throw new \Exception($ret['error']); + } + + return json_decode($result, true); + } + + + /* + public static function productsToCsv($products) + { + + // Имя файла CSV для сохранения данных + $csvFileName = 'productsPrjaProm_' . date("d-m-Y") . '.csv'; + + // Открываем файл CSV для записи (если файла нет, он будет создан) + $file = fopen($csvFileName, 'w'); + + // Записываем данные о продуктах + foreach ($products as $product) { + $row = []; + $attrs = $product->getAttrList(); + + $row['Код_товара'] = $product->item_code; + $row['Название_позиции'] = $product->itemname; + $row['Название_позиции_укр'] = $product->itemname; + $row['Поисковые_запросы'] = $product->itemname; + $row['Поисковые_запросы_укр'] = $product->itemname; + $row['Описание'] = $product->dscription; + $row['Описание_укр'] = $product->dscription; + + + + $row['Цена'] = round($product->price1); + $row['Валюта'] = 'UAH'; + $row['Единица_измерения'] = $product->msr; + $row['Оптовая_цена'] = round($product->price2); + + //картинки + $imgs = $product->getImages(); + $row['images'] = implode(",", array_map(function ($numberImage) { + return "https://vello-doro.eu/loadshopimage.php?id=" . $numberImage; + }, $imgs)); + $row['images'] .= ",https://vello-doro.eu/loadshopimage.php?id=" . $product->image_id; + + $row['Ссылка_изображения'] .= explode(',', $row['images'])[0]; + + $row['Наличие'] = '+'; + $row['Количество'] = '10000'; + $row['Номер_группы'] = '123627010'; + $row['Адрес_подраздела'] = 'https://prom.ua/Pryazha'; + $row['Возможность_поставки'] = ''; + $row['Срок_поставки'] = ''; + $row['Способ_упаковки'] = ''; + $row['Способ_упаковки_укр'] = ''; + $row['Уникальный_идентификатор'] = $product->item_code; + $row['Идентификатор_товара'] = $product->item_code; + $row['Идентификатор_подраздела'] = 408; + $row['Идентификатор_группы'] = ''; + $row['Производитель'] = $product->manufacturer; + $row['Страна_производитель'] = $product->country; + $row['Скидка'] = ''; + $row['ID_группы_разновидностей'] = ''; + $row['Личные_заметки'] = ''; + $row['Продукт_на_сайте'] = ''; + $row['Срок_действия_скидки_от'] = ''; + $row['Срок_действия_скидки_до'] = ''; + $row['Цена_от'] = ''; + $row['Ярлык'] = ''; + $row['HTML_заголовок'] = ''; + $row['HTML_заголовок_укр'] = ''; + $row['HTML_описание'] = ''; + $row['HTML_описание_укр'] = ''; + $row['Код_маркировки_(GTIN)'] = ''; + $row['Номер_устройства_(MPN)'] = ''; + $row['Вес,кг'] = ''; + $row['Ширина,см'] = ''; + $row['Высота,см'] = ''; + $row['Длина,см'] = ''; + $row['Где_находится_товар'] = ''; + + $row['Название_Характеристики'] = 'Стан'; + $row['Измерение_Характеристики'] = ''; + $row['Значение_Характеристики'] = 'Нове'; + + + $arrProducts[] = $row; + } + + // Устанавливаем точку с запятой как разделитель + $delimiter = ';'; + + // Устанавливаем кодировку для текста + $encoding = 'windows-1251'; + + + // Записываем заголовки столбцов (если необходимо) + if (!empty($arrProducts)) { + $columns = array_keys($arrProducts[0]); + + foreach ($attrs as $attr) { + $columns [] = 'Название_Характеристики'; + $columns [] = 'Измерение_Характеристики'; + $columns [] = 'Значение_Характеристики'; + } + + $fields = array_map(function ($field) use ($encoding) { + return iconv('UTF-8', $encoding, $field); + }, $columns); + + fputcsv($file, $fields, ';'); + } + + foreach ($products as $product) { + $row = []; + $attrs = $product->getAttrList(); + } + + // Записываем данные о продуктах + $i = 0; + foreach ($arrProducts as $arrProduct) { + + $attrs = $products[$i]->getAttrList(); + $i++; + + $values = array_values($arrProduct); + + foreach ($attrs as $attr) { + $values [] = $attr->attributename; + $values [] = ''; + $values [] = $attr->value; + } + + $fields = array_map(function ($field) use ($encoding) { + return iconv('UTF-8', $encoding, $field); + }, $values); + + fputcsv($file, $fields, ';'); + } + + // Закрываем файл + fclose($file); + + } + */ + + +} diff --git a/www/app/modules/hr/items.php b/www/app/modules/hr/items.php new file mode 100644 index 000000000..35e12b94c --- /dev/null +++ b/www/app/modules/hr/items.php @@ -0,0 +1,426 @@ +modules, 'promua') === false && System::getUser()->rolename != 'admins') { + System::setErrorMsg("Немає права доступу до сторінки"); + + App::RedirectError(); + return; + } + $modules = System::getOptions("modules"); + + $this->add(new Form('filter'))->onSubmit($this, 'filterOnSubmit'); + $this->filter->add(new DropDownChoice('searchcat', \App\Entity\Category::getList(), 0)); + + $this->add(new Form('exportform'))->onSubmit($this, 'exportOnSubmit'); + + $this->exportform->add(new DataView('newitemlist', new ArrayDataSource(new Prop($this, '_items')), $this, 'itemOnRow')); + $this->exportform->newitemlist->setPageSize(H::getPG()); + $this->exportform->add(new \Zippy\Html\DataList\Paginator('pag', $this->exportform->newitemlist)); + // $this->exportform->add(new DropDownChoice('ecat', $cats, 0)); + + $this->add(new Form('upd')); + $this->upd->add(new DropDownChoice('updcat', \App\Entity\Category::getList(), 0)); + + $this->upd->add(new SubmitLink('updateqty'))->onClick($this, 'onUpdateQty'); + $this->upd->add(new SubmitLink('updateprice'))->onClick($this, 'onUpdatePrice'); + + + $this->add(new Form('importform'))->onSubmit($this, 'importOnSubmit'); + $this->importform->add(new CheckBox('createcat')); + + + } + + + + public function filterOnSubmit($sender) { + $this->_items = array(); + $modules = System::getOptions("modules"); + $products = array(); + try { + $last_id=0; + while(true) { + $data = Helper::make_request("GET", "/api/v1/products/list?last_id=".$last_id, null); + if(count($data['products'])==0) { + break; + } + foreach ($data['products'] as $product) { + $products[]=$product; + $last_id = $product['id'] ; + } + } + + + + + } catch(\Exception $ee) { + System::setErrorMsg($ee->getMessage()); + return; + } + $sku = array(); + foreach ($products as $product) { + + if (strlen($product['sku']) == 0) { + continue; + } + $sku[]= $product['sku']; + } + + $cat = $this->filter->searchcat->getValue(); + $where = "disabled <> 1 "; + if ($cat > 0) { + $where .= " and cat_id=" . $cat; + } + + foreach (Item::findYield($where, "itemname") as $item) { + if (strlen($item->item_code) == 0) { + continue; + } + if (in_array($item->item_code, $sku)) { + continue; + } //уже в магазине + $item->qty = $item->getQuantity(); + + if (strlen($item->qty) == 0) { + $item->qty = 0; + } + $this->_items[] = $item; + } + + $this->exportform->newitemlist->Reload(); + //$this->exportform->ecat->setValue(0); + + } + + public function itemOnRow($row) { + $modules = System::getOptions("modules"); + + $item = $row->getDataItem(); + $row->add(new CheckBox('ch', new Prop($item, 'ch'))); + $row->add(new Label('name', $item->itemname)); + $row->add(new Label('code', $item->item_code)); + $row->add(new Label('qty', \App\Helper::fqty($item->qty))); + $row->add(new Label('price', $item->getPrice($modules['ocpricetype']))); + $row->add(new Label('desc', $item->desription)); + } + + public function exportOnSubmit($sender) { + $modules = System::getOptions("modules"); +// $cat = $this->exportform->ecat->getValue(); + + $elist = array(); + foreach ($this->_items as $item) { + if ($item->ch == false) { + continue; + } + $elist[] = array('name' => $item->itemname, + 'sku' => $item->item_code, + 'quantity_in_stock' => \App\Helper::fqty($item->qty), + 'price' => \App\Helper::fa($item->getPrice($modules['pupricetype'])) + ); + } + if (count($elist) == 0) { + + $this->setError('Не обрано товар'); + return; + } + $data = json_encode($elist, JSON_UNESCAPED_UNICODE); + + + + try { + $data = Helper::make_request("POST", "/api/v1/products/import_file", $data); + } catch(\Exception $ee) { + System::setErrorMsg($ee->getMessage()); + return; + } + + $this->setSuccess("Експортовано ".count($elist)." товарів"); + + //обновляем таблицу + $this->filterOnSubmit(null); + } + + public function onUpdateQty($sender) { + + $cat = $this->upd->updcat->getValue(); + $modules = System::getOptions("modules"); + + $elist = array(); + + foreach (Item::findYield("disabled <> 1 ". ($cat>0 ? " and cat_id=".$cat : "")) as $item) { + if (strlen($item->item_code) == 0) { + continue; + } + + $qty = $item->getQuantity(); + $elist[$item->item_code] = H::fqty($qty); + } + + + $products = array(); + try { + $last_id=0; + while(true) { + $data = Helper::make_request("GET", "/api/v1/products/list?last_id=".$last_id, null); + if(count($data['products'])==0) { + break; + } + foreach ($data['products'] as $product) { + $products[]=$product; + $last_id = $product['id'] ; + } + } + + + + + } catch(\Exception $ee) { + System::setErrorMsg($ee->getMessage()); + return; + } + $sku = array(); + foreach ($products as $product) { + + if (strlen($product['sku']) == 0) { + continue; + } + $sku[$product['sku']]= $product['id']; + } + + $list = array(); + foreach ($elist as $code=>$qty) { + + if($sku[$code]>0) { + $list[] = array('sku' => $sku[$code], + + 'quantity_in_stock' =>$elist[$code] + + ); + } + } + + $data = json_encode($list, JSON_UNESCAPED_UNICODE); + + + + try { + $data = Helper::make_request("POST", "/api/v1/products/edit", $data); + } catch(\Exception $ee) { + System::setErrorMsg($ee->getMessage()); + return; + } + + $this->setSuccess('Оновлено'); + } + + public function onUpdatePrice($sender) { + $modules = System::getOptions("modules"); + $cat = $this->upd->updcat->getValue(); + + $elist = array(); + + foreach (Item::findYield("disabled <> 1 ". ($cat>0 ? " and cat_id=".$cat : "")) as $item) { + if (strlen($item->item_code) == 0) { + continue; + } + + $elist[$item->item_code] = \App\Helper::fa($item->getPrice($modules['pupricetype'])); + } + + $products = array(); + try { + $last_id=0; + while(true) { + $data = Helper::make_request("GET", "/api/v1/products/list?last_id=".$last_id, null); + if(count($data['products'])==0) { + break; + } + foreach ($data['products'] as $product) { + $products[]=$product; + $last_id = $product['id'] ; + } + } + + + + + } catch(\Exception $ee) { + System::setErrorMsg($ee->getMessage()); + return; + } + $sku = array(); + foreach ($products as $product) { + + if (strlen($product['sku']) == 0) { + continue; + } + $sku[$product['sku']]= $product['id']; + } + + $list = array(); + foreach ($elist as $code=>$price) { + + if($sku[$code]>0) { + $list[] = array('sku' => $sku[$code], + + + 'price' =>$price + + ); + } + } + + $data = json_encode($list, JSON_UNESCAPED_UNICODE); + + + + try { + $data = Helper::make_request("POST", "/api/v1/products/edit", $data); + } catch(\Exception $ee) { + System::setErrorMsg($ee->getMessage()); + return; + } + + $this->setSuccess('Оновлено'); + } + + public function importOnSubmit($sender) { + $modules = System::getOptions("modules"); + $common = System::getOptions("common"); + + + $elist = array(); + $products = array(); + try { + $last_id=0; + while(true) { + $data = Helper::make_request("GET", "/api/v1/products/list?last_id=".$last_id, null); + if(count($data['products'])==0) { + break; + } + foreach ($data['products'] as $product) { + $products[]=$product; + $last_id = $product['id'] ; + } + } + + + + + } catch(\Exception $ee) { + System::setErrorMsg($ee->getMessage()); + return; + } + + + // $this->setInfo($json); + $i = 0; + foreach ($products as $product) { + + if (strlen($product['sku']) == 0) { + continue; + } + $cnt = Item::findCnt("item_code=" . Item::qstr($product['sku'])); + if ($cnt > 0) { + continue; + } //уже есть с таким артикулом + + $product['name'] = str_replace('"', '"', $product['name']); + $item = new Item(); + $item->item_code = $product['sku']; + $item->itemname = $product['name']; + // $item->description = $product['description']; + + if ($modules['pupricetype'] == 'price1') { + $item->price1 = $product['price']; + } + if ($modules['pupricetype'] == 'price2') { + $item->price2 = $product['price']; + } + if ($modules['pupricetype'] == 'price3') { + $item->price3 = $product['price']; + } + if ($modules['pupricetype'] == 'price4') { + $item->price4 = $product['price']; + } + if ($modules['pupricetype'] == 'price5') { + $item->price5 = $product['price']; + } + + + if ($common['useimages'] == 1) { + $im = $product['main_image']; + $im = @file_get_contents($im); + if (strlen($im) > 0) { + $imagedata = getimagesizefromstring($im); + $image = new \App\Entity\Image(); + $image->content = $im; + $image->mime = $imagedata['mime']; + $conn = \ZDB\DB::getConnect(); + if($conn->dataProvider=='postgres') { + $image->thumb = pg_escape_bytea($image->thumb); + $image->content = pg_escape_bytea($image->content); + + } + + $image->save(); + $item->image_id = $image->image_id; + } + } + + $cat_name =trim($product['group']['name']); + if($sender->createcat->isChecked() && strlen($cat_name)>0) { + + + $cat_name = str_replace(' ', '', $cat_name) ; + if(strpos($cat_name, '>')>0) { + $ar = explode('>', $cat_name) ; + $cat_name = trim($ar[count($ar)-1]); + + } + $cat = \App\Entity\Category::getFirst("cat_name=" . \App\Entity\Category::qstr($cat_name)) ; + + if($cat == null) { + $cat = new \App\Entity\Category(); + $cat->cat_name = $cat_name; + $cat->save(); + + } + + $item->cat_id=$cat->cat_id; + + } + + + $item->save(); + $i++; + } + + $this->setSuccess("Завантажено {$i} товарів"); + } + +} diff --git a/www/app/modules/hr/options.php b/www/app/modules/hr/options.php new file mode 100644 index 000000000..4e0db08f8 --- /dev/null +++ b/www/app/modules/hr/options.php @@ -0,0 +1,80 @@ +modules, 'promua') === false && System::getUser()->rolename != 'admins') { + System::setErrorMsg("Немає права доступу до сторінки"); + + App::RedirectError(); + return; + } + + $modules = System::getOptions("modules"); + + + $form = $this->add(new Form("cform")); + + $form->add(new TextInput('apitoken', $modules['puapitoken'])); + + + $form->add(new DropDownChoice('defpricetype', \App\Entity\Item::getPriceTypeList(), $modules['pupricetype'])); + + $form->add(new CheckBox('setpayamount', $modules['pusetpayamount'])); + $form->add(new DropDownChoice('salesource', \App\Helper::getSaleSources(), $modules['pusalesource'])); + $form->add(new CheckBox('ssl', $modules['pussl'])); + + $form->add(new SubmitButton('save'))->onClick($this, 'saveOnClick'); + $form->add(new CheckBox('insertcust', $modules['puinsertcust'])); + + } + //584ac4cc9096eb799cf6664ce977b22c6f463cba + + public function saveOnClick($sender) { + + $apitoken = $this->cform->apitoken->getText(); + $setpayamount = $this->cform->setpayamount->isChecked() ? 1 : 0; + + $pricetype = $this->cform->defpricetype->getValue(); + $salesource = $this->cform->salesource->getValue(); + $insertcust = $this->cform->insertcust->isChecked() ? 1 : 0; + + if (strlen($pricetype) < 2) { + $this->setError('Не вказано тип ціни'); + return; + } + + // $site = trim($site, '/'); + + $modules = System::getOptions("modules"); + + // $modules['pusite'] = "http://my.prom.ua/"; + $modules['puapitoken'] = $apitoken; + + $modules['pupricetype'] = $pricetype; + $modules['pusalesource'] = $salesource; + $modules['pusetpayamount'] = $setpayamount; + $modules['puinsertcust'] = $insertcust; + $modules['pussl'] = $this->cform->ssl->isChecked() ? 1 : 0;; + + System::setOptions("modules", $modules); + $this->setSuccess('Збережено'); + + \App\Modules\HR\Helper::connect(); + + + } + +} diff --git a/www/app/modules/hr/orders.php b/www/app/modules/hr/orders.php new file mode 100644 index 000000000..ae25176a2 --- /dev/null +++ b/www/app/modules/hr/orders.php @@ -0,0 +1,279 @@ +modules, 'promua') === false && System::getUser()->rolename != 'admins') { + System::setErrorMsg("Немає права доступу до сторінки") ; + + App::RedirectError(); + return; + } + + $modules = System::getOptions("modules"); + + $statuses = Helper::connect() ; + + $this->add(new Form('filter'))->onSubmit($this, 'filterOnSubmit'); + $this->filter->add(new DropDownChoice('status', $statuses, 'pending')); + + $this->add(new DataView('neworderslist', new ArrayDataSource(new Prop($this, '_neworders')), $this, 'noOnRow')); + + $this->add(new ClickLink('importbtn'))->onClick($this, 'onImport'); + + $this->add(new ClickLink('refreshbtn'))->onClick($this, 'onRefresh'); + $this->add(new Form('updateform'))->onSubmit($this, 'exportOnSubmit'); + $this->updateform->add(new DataView('orderslist', new ArrayDataSource(new Prop($this, '_eorders')), $this, 'expRow')); + $this->updateform->add(new DropDownChoice('estatus', $statuses, 'delivered')); + + + } + + + public function filterOnSubmit($sender) { + $modules = System::getOptions("modules"); + + $client = \App\Modules\WC\Helper::getClient(); + + $this->_neworders = array(); + + + try { + $data = Helper::make_request("GET", "/api/v1/orders/list?status=". $this->filter->status->getValue(), null); + + } catch(\Exception $ee) { + $this->setErrorTopPage($ee->getMessage()); + return; + } + + + $conn = \ZDB\DB::getConnect(); + + foreach ($data['orders'] as $puorder) { + + $cnt = $conn->getOne("select count(*) from documents_view where meta_name='Order' and content like '%{$puorder['id']}%' ") ; + + + if (intval($cnt) > 0) { //уже импортирован + continue; + } + + $neworder = Document::create('Order'); + + + //товары + $j=0; + $itlist = array(); + foreach ($puorder['products'] as $product) { + //ищем по артикулу + if (strlen($product['sku']) == 0) { + continue; + } + $code = Item::qstr($product['sku']); + + $tovar = Item::getFirst('item_code=' . $code); + if ($tovar == null) { + + $this->setWarn("Не знайдено артикул товара {$product['name']} в замовленні номер " . $puorder['order_id']); + continue; + } + $tovar->quantity = H::fqty($product['quantity']); + $tovar->price = H::fa($product['price']); + $j++; + $tovar->rowid = $j; + + $itlist[$j] = $tovar; + } + + if(count($itlist)==0) { + return; + } + $neworder->packDetails('detaildata', $itlist); + $neworder->headerdata['pricetype'] = 'price1'; + + $neworder->headerdata['cemail'] = $puorder['email']; + $neworder->headerdata['cname'] = $puorder['client_first_name'] . ' ' . $puorder['client_last_name']; + $neworder->headerdata['cphone'] = $puorder['phone'] ; + $neworder->headerdata['puorder'] = $puorder['id']; + $neworder->headerdata['outnumber'] = $puorder['id']; + $neworder->headerdata['puorderback'] = 0; + $neworder->headerdata['salesource'] = $modules['pusalesource']; + + $neworder->headerdata['puclient'] = $puorder['client_first_name'] . ' ' . $puorder['client_last_name']; + + $neworder->amount = H::fa($puorder['price']); + $neworder->payamount = H::fa($puorder['full_price']); + + + $neworder->document_date = time(); + $neworder->notes = "PU номер:{$puorder['id']};"; + $neworder->notes .= " Клієнт:" .$puorder['client_first_name'] . ' ' . $puorder['client_last_name'].';'; + if (strlen($puorder['email']) > 0) { + $neworder->notes .= " Email:" . $puorder['email'] . ";"; + } + if (strlen($puorder['phone']) > 0) { + $neworder->notes .= " Тел:" . str_replace('+', '', $puorder['phone']). ";"; + } + if (strlen($puorder['delivery_option']['name']) > 0) { + $neworder->notes .= " Доставка:" . $puorder['delivery_option']['name'] . ";"; + } + + if (strlen($puorder['delivery_address']) > 0) { + $neworder->notes .= " Адреса:" . $puorder['delivery_address'] . ";"; + } + if (strlen($puorder['client_notes']) > 0) { + $neworder->notes .= " Комментар:" . $puorder['client_notes'] . ";"; + } + + + $this->_neworders[$puorder['id']] = $neworder; + } + + $this->neworderslist->Reload(); + } + + public function noOnRow($row) { + $order = $row->getDataItem(); + + $row->add(new Label('number', $order->headerdata['puorder'])); + $row->add(new Label('customer', $order->headerdata['puclient'])); + $row->add(new Label('amount', round($order->amount))); + $row->add(new Label('comment', $order->notes)); + $row->add(new Label('date', \App\Helper::fdt(strtotime($order->document_date)))); + } + + public function onImport($sender) { + $modules = System::getOptions("modules"); + + foreach ($this->_neworders as $shoporder) { + $shoporder->document_number = $shoporder->nextNumber(); + if (strlen($shoporder->document_number) == 0) { + $shoporder->document_number = 'PU00001'; + } + + if ( $modules['puinsertcust'] == 1) { + $phone = \App\Util::handlePhone($shoporder->headerdata['cphone'] ) ; + $cust = Customer::getByPhone($phone); + if ($cust == null) { + $cust = Customer::getByEmail($shoporder->headerdata['cemail']); + } + if ($cust == null &&strlen($shoporder->headerdata['cname']) >0 && ( strlen($phone) >0 || strlen($shoporder->headerdata['cemail'])>0 ) ) { + $cust = new Customer(); + $cust->customer_name = $shoporder->headerdata['cname']; + $cust->phone = $phone; + + $cust->type = Customer::TYPE_BAYER; + + $cust->email = $shoporder->headerdata['cemail']; + $cust->comment = "Клiєнт Prom UA"; + $cust->save(); + } + if($cust != null) { + $shoporder->customer_id = $cust->customer_id; + } + } + + + $shoporder->save(); + $shoporder->updateStatus(Document::STATE_NEW); + $shoporder->updateStatus(Document::STATE_INPROCESS); + if($modules['pusetpayamount']==1) { + $shoporder->updateStatus(Document::STATE_WP); + } + + + } + + $this->setInfo("Імпортовано ".count($this->_neworders)." замовлень"); + + $this->_neworders = array(); + $this->neworderslist->Reload(); + } + + public function onRefresh($sender) { + + $this->_eorders = Document::find("meta_name='Order' and content like '%0%' and state <> " . Document::STATE_NEW); + $this->updateform->orderslist->Reload(); + } + + public function expRow($row) { + $order = $row->getDataItem(); + $row->add(new CheckBox('ch', new Prop($order, 'ch'))); + $row->add(new Label('number2', $order->document_number)); + $row->add(new Label('number3', $order->headerdata['puorder'])); + $row->add(new Label('date2', \App\Helper::fdt($order->document_date))); + $row->add(new Label('amount2', $order->amount)); + $row->add(new Label('customer2', $order->headerdata['puclient'])); + $row->add(new Label('state', Document::getStateName($order->state))); + } + + public function exportOnSubmit($sender) { + $modules = System::getOptions("modules"); + $st = $this->updateform->estatus->getValue(); + + + $elist = array(); + foreach ($this->_eorders as $order) { + if ($order->ch == false) { + continue; + } + $elist[] = $order; + } + if (count($elist) == 0) { + $this->setError('Не обрано ордер'); + return; + } + + $fields = array( + 'status' => $st + ); + + foreach ($elist as $order) { + + + try { + $json="{ + \"status\":\"pending\", + \"ids\":[{$order->headerdata['ocorder']}] + }" ; + Helper::make_request("POST", "/api/v1/orders/set_status", $json); + } catch(\Exception $ee) { + $this->setErrorTopPage($ee->getMessage()); + return; + } + + $order->headerdata['puorderback'] = 1; + $order->save(); + } + + $this->setSuccess("Оновлено ".count($elist)." замовлень"); + + + + $this->_eorders = Document::find("meta_name='Order' and content like '%0%' and state <> " . Document::STATE_NEW); + $this->updateform->orderslist->Reload(); + } + +} diff --git a/www/app/pages/base.php b/www/app/pages/base.php index ca4af6035..dd7215ac9 100644 --- a/www/app/pages/base.php +++ b/www/app/pages/base.php @@ -129,6 +129,7 @@ public function __construct($params = null) { $this->_tvars["paperless"] = $modules['paperless'] == 1; $this->_tvars["checkbox"] = $modules['checkbox'] == 1; $this->_tvars["vkassa"] = $modules['vkassa'] == 1; + $this->_tvars["horoshop"] = $modules['horoshop'] == 1; // $printer = System::getOptions('printer'); @@ -175,6 +176,9 @@ public function __construct($params = null) { if (strpos(System::getUser()->modules ?? '', 'vkassa') === false && System::getUser()->rolename != 'admins') { $this->_tvars["vkassa"] = false; } + if (strpos(System::getUser()->modules ?? '', 'vkassa') === false && System::getUser()->rolename != 'admins') { + $this->_tvars["vkassa"] = false; + } $this->_tvars["fiscal"] = $this->_tvars["checkbox"] || $this->_tvars["ppo"] || $this->_tvars["vkassa"]; @@ -186,7 +190,7 @@ public function __construct($params = null) { $this->_tvars["promua"] || $this->_tvars["paperless"] || $this->_tvars["ppo"] || - + $this->_tvars["horoshop"] || $this->_tvars["np"] ) { $this->_tvars["showmodmenu"] = true; diff --git a/www/app/pages/options.php b/www/app/pages/options.php index dac15c1b7..06449c042 100644 --- a/www/app/pages/options.php +++ b/www/app/pages/options.php @@ -333,10 +333,9 @@ public function __construct() { $this->modules->add(new CheckBox('modwoocomerce', $modules['woocomerce'])); $this->modules->add(new CheckBox('modnp', $modules['np'])); $this->modules->add(new CheckBox('modpromua', $modules['promua'])); + $this->modules->add(new CheckBox('modhoroshop', $modules['horoshop'])); $this->modules->add(new CheckBox('modpaperless', $modules['paperless'])); -// $this->modules->add(new CheckBox('modppo', $modules['ppo'])); -// $this->modules->add(new CheckBox('modcheckbox', $modules['checkbox'])); - +// $fisctype=0; if($modules['ppo']==1) $fisctype=1; @@ -682,6 +681,7 @@ public function onModules($sender) { $modules['woocomerce'] = $sender->modwoocomerce->isChecked() ? 1 : 0; $modules['np'] = $sender->modnp->isChecked() ? 1 : 0; $modules['promua'] = $sender->modpromua->isChecked() ? 1 : 0; + $modules['horoshop'] = $sender->modhoroshop->isChecked() ? 1 : 0; $modules['paperless'] = $sender->modpaperless->isChecked() ? 1 : 0; $modules['issue'] = $sender->modissue->isChecked() ? 1 : 0; $modules['note'] = $sender->modnote->isChecked() ? 1 : 0; diff --git a/www/app/pages/roles.php b/www/app/pages/roles.php index 263fbc3c5..ff1d474d4 100644 --- a/www/app/pages/roles.php +++ b/www/app/pages/roles.php @@ -69,6 +69,7 @@ public function __construct() { $this->editpan->editform->add(new CheckBox('editpl')); $this->editpan->editform->add(new CheckBox('editcb')); $this->editpan->editform->add(new CheckBox('editvk')); + $this->editpan->editform->add(new CheckBox('edithr')); $this->editpan->editform->add(new Button('cancel'))->onClick($this, 'cancelOnClick'); @@ -196,6 +197,9 @@ public function OnAcl($sender) { if (strpos($this->role->modules, 'vkassa') !== false) { $this->editpan->editform->editvk->setChecked(true); } + if (strpos($this->role->modules, 'horoshop') !== false) { + $this->editpan->editform->edithr->setChecked(true); + } } public function savenameOnClick($sender) { @@ -330,6 +334,9 @@ public function saveaclOnClick($sender) { if ($this->editpan->editform->editvk->isChecked()) { $modules = $modules . ',vkassa'; } + if ($this->editpan->editform->edithr->isChecked()) { + $modules = $modules . ',horoshop'; + } $this->role->modules = trim($modules, ','); diff --git a/www/app/system.php b/www/app/system.php index cfb50f15a..876893ff4 100644 --- a/www/app/system.php +++ b/www/app/system.php @@ -10,7 +10,7 @@ */ class System { - public const CURR_VERSION= "6.8.10"; + public const CURR_VERSION= "6.8.11"; public const REQUIRED_DB= "6.8.0"; private static $_options = array(); // для кеширования diff --git a/www/templates/modules/hr/items.html b/www/templates/modules/hr/items.html new file mode 100644 index 000000000..07132d471 --- /dev/null +++ b/www/templates/modules/hr/items.html @@ -0,0 +1,132 @@ + + + +
+ + {{#hideblock}} +
+ +

Експорт товарів в магазин

+    Спецсимволи (типу & ' " `) + в назвi або описi може викликати проблеми з вигрузкою + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
НайменуванняАртикулКіл.Ціна Опис
+
+
+ + +   + +
+
+
+ + {{/hideblock}} +
+ +

Оновлення цін та кількості

+ + +
+ +
+ +

Iмпорт товарів з магазину

+ + +
+
+ + + diff --git a/www/templates/modules/hr/options.html b/www/templates/modules/hr/options.html new file mode 100644 index 000000000..89bd31cea --- /dev/null +++ b/www/templates/modules/hr/options.html @@ -0,0 +1,68 @@ + + + + +
+
+

Налаштування з'єднання

+
+ +
+ + +
+ + +
+ + +
+ +
+ + + + +
+
+ + + +
+
+
+ + + Iмпортувати клiєнтiв з IМ в довiдник контрагентiв. +
+
+
+ + + +
+
+ + + + +
+
+
+
+ + + + diff --git a/www/templates/modules/hr/orders.html b/www/templates/modules/hr/orders.html new file mode 100644 index 000000000..5079e5471 --- /dev/null +++ b/www/templates/modules/hr/orders.html @@ -0,0 +1,121 @@ + + +
+
+ +

Імпорт замовлень

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
НомерДатаКлієнтСума Коментар
+ +
+
+ +

Експорт статусів в магазин

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
НомерPU НомерДатаКлієнтСумаСтатус
+ + +
+ + + + + + +
+
+ +
+
+ + + + diff --git a/www/templates/pages/base.html b/www/templates/pages/base.html index d90398b2d..871718da2 100644 --- a/www/templates/pages/base.html +++ b/www/templates/pages/base.html @@ -874,6 +874,41 @@ {{/promua}} + {{#horoshop}} + + {{/horoshop}} + diff --git a/www/templates/pages/options.html b/www/templates/pages/options.html index 1574fc741..f0a13af3b 100644 --- a/www/templates/pages/options.html +++ b/www/templates/pages/options.html @@ -196,6 +196,11 @@

Підключення модулів

+
+ + + +
diff --git a/www/templates/pages/roles.html b/www/templates/pages/roles.html index 7a125314f..f16b87cea 100644 --- a/www/templates/pages/roles.html +++ b/www/templates/pages/roles.html @@ -288,6 +288,16 @@

Редагування доступу

{{/vkassa}} + {{#horoshop}} + + + + + + + + {{/horoshop}} +
From 0c93987e79d5b2985cf9538655ca968a2cadd80e Mon Sep 17 00:00:00 2001 From: "leon.mbs@gmail.com" Date: Wed, 20 Dec 2023 16:19:55 +0200 Subject: [PATCH 02/13] HR connect --- www/app/modules/hr/helper.php | 167 +++----------------------- www/app/modules/hr/items.php | 2 +- www/app/modules/hr/options.php | 45 ++++--- www/app/modules/hr/orders.php | 2 +- www/templates/modules/hr/options.html | 35 +++--- www/templates/pages/options.html | 2 +- 6 files changed, 61 insertions(+), 192 deletions(-) diff --git a/www/app/modules/hr/helper.php b/www/app/modules/hr/helper.php index cc616d256..5ba6f421a 100644 --- a/www/app/modules/hr/helper.php +++ b/www/app/modules/hr/helper.php @@ -11,11 +11,15 @@ class Helper { public static function connect() { - + $modules = System::getOptions("modules"); + $body = []; + $body['login'] = $modules['hrlogin']; + $body['password'] = $modules['hrpassword']; + try { - $ret = self::make_request("GET", "/api/v1/order_status_options/list", null); + $ret = self::make_request("POST", "/api/auth", json_encode($body)); } catch(\Exception $ee) { System::setErrorMsg($ee->getMessage()); return; @@ -26,28 +30,27 @@ public static function connect() { return; } - $list = array(); - foreach($ret['order_status_options'] as $st) { - $list[$st['name']]=$st['title'] ; + if(($ret['token'] ??'')=='') { + System::setErrorMsg('Invalid token'); + return; } - return $list; + return $ret['token'] ??''; } public static function make_request($method, $url, $body='') { $modules = System::getOptions("modules"); - $usessl = $modules['pussl']; + $usessl = $modules['hrssl']; $headers = array( - 'Authorization: Bearer ' . $modules['puapitoken'], 'Content-Type: application/json' ); $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, 'https://my.prom.ua' . $url); + curl_setopt($ch, CURLOPT_URL, $modules['hrsite'] . $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); if (strtoupper($method) == 'POST') { @@ -72,151 +75,11 @@ public static function make_request($method, $url, $body='') { curl_close($ch); $ret = json_decode($result, true) ; - if (strlen($ret['error']) > 0) { - throw new \Exception($ret['error']); + if (strlen($ret['status']=='error') ) { + throw new \Exception($ret['response']['message']); } - return json_decode($result, true); + return $ret['response']; } - - /* - public static function productsToCsv($products) - { - - // Имя файла CSV для сохранения данных - $csvFileName = 'productsPrjaProm_' . date("d-m-Y") . '.csv'; - - // Открываем файл CSV для записи (если файла нет, он будет создан) - $file = fopen($csvFileName, 'w'); - - // Записываем данные о продуктах - foreach ($products as $product) { - $row = []; - $attrs = $product->getAttrList(); - - $row['Код_товара'] = $product->item_code; - $row['Название_позиции'] = $product->itemname; - $row['Название_позиции_укр'] = $product->itemname; - $row['Поисковые_запросы'] = $product->itemname; - $row['Поисковые_запросы_укр'] = $product->itemname; - $row['Описание'] = $product->dscription; - $row['Описание_укр'] = $product->dscription; - - - - $row['Цена'] = round($product->price1); - $row['Валюта'] = 'UAH'; - $row['Единица_измерения'] = $product->msr; - $row['Оптовая_цена'] = round($product->price2); - - //картинки - $imgs = $product->getImages(); - $row['images'] = implode(",", array_map(function ($numberImage) { - return "https://vello-doro.eu/loadshopimage.php?id=" . $numberImage; - }, $imgs)); - $row['images'] .= ",https://vello-doro.eu/loadshopimage.php?id=" . $product->image_id; - - $row['Ссылка_изображения'] .= explode(',', $row['images'])[0]; - - $row['Наличие'] = '+'; - $row['Количество'] = '10000'; - $row['Номер_группы'] = '123627010'; - $row['Адрес_подраздела'] = 'https://prom.ua/Pryazha'; - $row['Возможность_поставки'] = ''; - $row['Срок_поставки'] = ''; - $row['Способ_упаковки'] = ''; - $row['Способ_упаковки_укр'] = ''; - $row['Уникальный_идентификатор'] = $product->item_code; - $row['Идентификатор_товара'] = $product->item_code; - $row['Идентификатор_подраздела'] = 408; - $row['Идентификатор_группы'] = ''; - $row['Производитель'] = $product->manufacturer; - $row['Страна_производитель'] = $product->country; - $row['Скидка'] = ''; - $row['ID_группы_разновидностей'] = ''; - $row['Личные_заметки'] = ''; - $row['Продукт_на_сайте'] = ''; - $row['Срок_действия_скидки_от'] = ''; - $row['Срок_действия_скидки_до'] = ''; - $row['Цена_от'] = ''; - $row['Ярлык'] = ''; - $row['HTML_заголовок'] = ''; - $row['HTML_заголовок_укр'] = ''; - $row['HTML_описание'] = ''; - $row['HTML_описание_укр'] = ''; - $row['Код_маркировки_(GTIN)'] = ''; - $row['Номер_устройства_(MPN)'] = ''; - $row['Вес,кг'] = ''; - $row['Ширина,см'] = ''; - $row['Высота,см'] = ''; - $row['Длина,см'] = ''; - $row['Где_находится_товар'] = ''; - - $row['Название_Характеристики'] = 'Стан'; - $row['Измерение_Характеристики'] = ''; - $row['Значение_Характеристики'] = 'Нове'; - - - $arrProducts[] = $row; - } - - // Устанавливаем точку с запятой как разделитель - $delimiter = ';'; - - // Устанавливаем кодировку для текста - $encoding = 'windows-1251'; - - - // Записываем заголовки столбцов (если необходимо) - if (!empty($arrProducts)) { - $columns = array_keys($arrProducts[0]); - - foreach ($attrs as $attr) { - $columns [] = 'Название_Характеристики'; - $columns [] = 'Измерение_Характеристики'; - $columns [] = 'Значение_Характеристики'; - } - - $fields = array_map(function ($field) use ($encoding) { - return iconv('UTF-8', $encoding, $field); - }, $columns); - - fputcsv($file, $fields, ';'); - } - - foreach ($products as $product) { - $row = []; - $attrs = $product->getAttrList(); - } - - // Записываем данные о продуктах - $i = 0; - foreach ($arrProducts as $arrProduct) { - - $attrs = $products[$i]->getAttrList(); - $i++; - - $values = array_values($arrProduct); - - foreach ($attrs as $attr) { - $values [] = $attr->attributename; - $values [] = ''; - $values [] = $attr->value; - } - - $fields = array_map(function ($field) use ($encoding) { - return iconv('UTF-8', $encoding, $field); - }, $values); - - fputcsv($file, $fields, ';'); - } - - // Закрываем файл - fclose($file); - - } - */ - - } diff --git a/www/app/modules/hr/items.php b/www/app/modules/hr/items.php index 35e12b94c..efe4ba258 100644 --- a/www/app/modules/hr/items.php +++ b/www/app/modules/hr/items.php @@ -23,7 +23,7 @@ class Items extends \App\Pages\Base public function __construct() { parent::__construct(); - if (strpos(System::getUser()->modules, 'promua') === false && System::getUser()->rolename != 'admins') { + if (strpos(System::getUser()->modules, 'horoshop') === false && System::getUser()->rolename != 'admins') { System::setErrorMsg("Немає права доступу до сторінки"); App::RedirectError(); diff --git a/www/app/modules/hr/options.php b/www/app/modules/hr/options.php index 4e0db08f8..9a75d70ce 100644 --- a/www/app/modules/hr/options.php +++ b/www/app/modules/hr/options.php @@ -15,7 +15,7 @@ class Options extends \App\Pages\Base public function __construct() { parent::__construct(); - if (strpos(System::getUser()->modules, 'promua') === false && System::getUser()->rolename != 'admins') { + if (strpos(System::getUser()->modules, 'horoshop') === false && System::getUser()->rolename != 'admins') { System::setErrorMsg("Немає права доступу до сторінки"); App::RedirectError(); @@ -27,26 +27,29 @@ public function __construct() { $form = $this->add(new Form("cform")); - $form->add(new TextInput('apitoken', $modules['puapitoken'])); + $form->add(new TextInput('site', $modules['hrsite'])); + $form->add(new TextInput('login', $modules['hrlogin'])); + $form->add(new TextInput('password', $modules['hrpassword'])); - $form->add(new DropDownChoice('defpricetype', \App\Entity\Item::getPriceTypeList(), $modules['pupricetype'])); + $form->add(new DropDownChoice('defpricetype', \App\Entity\Item::getPriceTypeList(), $modules['hrpricetype'])); - $form->add(new CheckBox('setpayamount', $modules['pusetpayamount'])); - $form->add(new DropDownChoice('salesource', \App\Helper::getSaleSources(), $modules['pusalesource'])); - $form->add(new CheckBox('ssl', $modules['pussl'])); + + $form->add(new DropDownChoice('salesource', \App\Helper::getSaleSources(), $modules['hrsalesource'])); + $form->add(new CheckBox('ssl', $modules['hrssl'])); $form->add(new SubmitButton('save'))->onClick($this, 'saveOnClick'); - $form->add(new CheckBox('insertcust', $modules['puinsertcust'])); + $form->add(new CheckBox('insertcust', $modules['hrinsertcust'])); } //584ac4cc9096eb799cf6664ce977b22c6f463cba public function saveOnClick($sender) { - $apitoken = $this->cform->apitoken->getText(); - $setpayamount = $this->cform->setpayamount->isChecked() ? 1 : 0; - + $site = $this->cform->site->getText(); + $login = $this->cform->login->getText(); + $password = $this->cform->password->getText(); + $pricetype = $this->cform->defpricetype->getValue(); $salesource = $this->cform->salesource->getValue(); $insertcust = $this->cform->insertcust->isChecked() ? 1 : 0; @@ -56,24 +59,26 @@ public function saveOnClick($sender) { return; } - // $site = trim($site, '/'); + $site = trim($site, '/'); $modules = System::getOptions("modules"); - // $modules['pusite'] = "http://my.prom.ua/"; - $modules['puapitoken'] = $apitoken; + $modules['hrsite'] = $site; + $modules['hrlogin'] = $login; + $modules['hrpassword'] = $password; - $modules['pupricetype'] = $pricetype; - $modules['pusalesource'] = $salesource; - $modules['pusetpayamount'] = $setpayamount; - $modules['puinsertcust'] = $insertcust; - $modules['pussl'] = $this->cform->ssl->isChecked() ? 1 : 0;; + $modules['hrpricetype'] = $pricetype; + $modules['hrsalesource'] = $salesource; + $modules['hrinsertcust'] = $insertcust; + $modules['hrssl'] = $this->cform->ssl->isChecked() ? 1 : 0;; System::setOptions("modules", $modules); $this->setSuccess('Збережено'); - \App\Modules\HR\Helper::connect(); - + $token= \App\Modules\HR\Helper::connect(); + if(strlen($token)>0) { + $this->setSuccess('Успішне з`єднання '); + } } diff --git a/www/app/modules/hr/orders.php b/www/app/modules/hr/orders.php index ae25176a2..5e6ee9401 100644 --- a/www/app/modules/hr/orders.php +++ b/www/app/modules/hr/orders.php @@ -25,7 +25,7 @@ class Orders extends \App\Pages\Base public function __construct() { parent::__construct(); - if (strpos(System::getUser()->modules, 'promua') === false && System::getUser()->rolename != 'admins') { + if (strpos(System::getUser()->modules, 'horoshop') === false && System::getUser()->rolename != 'admins') { System::setErrorMsg("Немає права доступу до сторінки") ; App::RedirectError(); diff --git a/www/templates/modules/hr/options.html b/www/templates/modules/hr/options.html index 89bd31cea..759187e9d 100644 --- a/www/templates/modules/hr/options.html +++ b/www/templates/modules/hr/options.html @@ -6,19 +6,20 @@

Налаштування з'єднання

-
- - + + + Потрiбно вводити повну адресу +
+
+ +
- - -
- - -
+
+ + +
+
@@ -29,12 +30,12 @@

Налаштування з'єднання

-
- - - -
-
+
+ + +
diff --git a/www/templates/pages/options.html b/www/templates/pages/options.html index f0a13af3b..babfe95c3 100644 --- a/www/templates/pages/options.html +++ b/www/templates/pages/options.html @@ -199,7 +199,7 @@

Підключення модулів

- +
From 5fb711cc6900fd0a1bd91e6e0750ef24dc8ecc00 Mon Sep 17 00:00:00 2001 From: "leon.mbs@gmail.com" Date: Wed, 20 Dec 2023 21:31:18 +0200 Subject: [PATCH 03/13] import --- www/app/modules/hr/items.php | 527 ++++++++++++----------- www/app/pages/reference/categorylist.php | 1 + www/templates/modules/hr/items.html | 57 +-- 3 files changed, 317 insertions(+), 268 deletions(-) diff --git a/www/app/modules/hr/items.php b/www/app/modules/hr/items.php index efe4ba258..23eb5ad7d 100644 --- a/www/app/modules/hr/items.php +++ b/www/app/modules/hr/items.php @@ -3,6 +3,7 @@ namespace App\Modules\HR; use App\Entity\Item; +use App\Entity\Category; use App\Helper as H; use App\System; use Zippy\Binding\PropertyBinding as Prop; @@ -19,6 +20,8 @@ class Items extends \App\Pages\Base { public $_items = array(); + public $_pages = array(); + public $_origpages = array(); public function __construct() { parent::__construct(); @@ -30,6 +33,7 @@ public function __construct() { return; } $modules = System::getOptions("modules"); + $this->add(new Form('filter'))->onSubmit($this, 'filterOnSubmit'); $this->filter->add(new DropDownChoice('searchcat', \App\Entity\Category::getList(), 0)); @@ -39,7 +43,7 @@ public function __construct() { $this->exportform->add(new DataView('newitemlist', new ArrayDataSource(new Prop($this, '_items')), $this, 'itemOnRow')); $this->exportform->newitemlist->setPageSize(H::getPG()); $this->exportform->add(new \Zippy\Html\DataList\Paginator('pag', $this->exportform->newitemlist)); - // $this->exportform->add(new DropDownChoice('ecat', $cats, 0)); + $this->exportform->add(new DropDownChoice('ecat', $cats, 0)); $this->add(new Form('upd')); $this->upd->add(new DropDownChoice('updcat', \App\Entity\Category::getList(), 0)); @@ -48,71 +52,141 @@ public function __construct() { $this->upd->add(new SubmitLink('updateprice'))->onClick($this, 'onUpdatePrice'); + $this->add(new ClickLink('checkconn'))->onClick($this, 'onCheck'); + + + $this->add(new Form('importform'))->onSubmit($this, 'importOnSubmit'); - $this->importform->add(new CheckBox('createcat')); + } + public function onCheck($sender) { - - public function filterOnSubmit($sender) { - $this->_items = array(); - $modules = System::getOptions("modules"); - $products = array(); + $token= \App\Modules\HR\Helper::connect(); + if(strlen($token)==0) { + return; + } try { - $last_id=0; - while(true) { - $data = Helper::make_request("GET", "/api/v1/products/list?last_id=".$last_id, null); - if(count($data['products'])==0) { - break; - } - foreach ($data['products'] as $product) { - $products[]=$product; - $last_id = $product['id'] ; + $this->_pages=[]; + $this->_origpages=[]; + $body=[]; + $body['token'] =$token; + + + $ret = \App\Modules\HR\Helper::make_request("POST", "/api/pages/export", json_encode($body, JSON_UNESCAPED_UNICODE)); + $pages=[]; + $parents=[]; + $images=[]; + foreach($ret['pages'] as $p){ + if($p['parent'] <2) continue; + $name=$p['title']['ua'] ??'' ; + if($name=='') { + $name=$p['title']['ru'] ??'' ; + } + + $id = $p['id'] ; + + $pages[$id] = $name ; + if(strlen($p['image'] ??'') >0 ) { + $images[$id] = $p['image'] ; + } + + $parents[]=$p['parent'] ; + }; + + foreach($pages as $i=>$name){ + if(in_array($i,$parents)==false) { + $this->_pages[$i]=$name; + + $c= Category::getFirst('cat_name='.Category::qstr($name)) ; + if($c==null){ + $c = new Category(); + $c->cat_name = $name; + $c->save(); + + if(isset($images[$i] )) { + $im = @file_get_contents($images[$i]); + if (strlen($im) > 0) { + $imagedata = getimagesizefromstring($im); + $image = new \App\Entity\Image(); + $image->content = $im; + $image->mime = $imagedata['mime']; + + if($conn->dataProvider=='postgres') { + $image->thumb = pg_escape_bytea($image->thumb); + $image->content = pg_escape_bytea($image->content); + + } + $image->save(); + $c->image_id = $image->image_id; + $c->save(); + } + } + } + $this->_origpages[$i] = $c->cat_id; + + + } } + + + } catch(\Exception $ee) { + $this->setErrorTopPage($ee->getMessage()); + return; } + } - - - } catch(\Exception $ee) { - System::setErrorMsg($ee->getMessage()); + public function filterOnSubmit($sender) { + $this->_items = array(); + $modules = System::getOptions("modules"); + $url = $modules['ocsite'] . '/index.php?route=api/zstore/articles&' . System::getSession()->octoken; + if($modules['ocv4']==1) { + $url = $modules['ocsite'] . '/index.php?route=api/zstore.articles&' . System::getSession()->octoken; + } + $json = Helper::do_curl_request($url); + if ($json === false) { return; } - $sku = array(); - foreach ($products as $product) { + $data = json_decode($json, true); + if (!isset($data)) { - if (strlen($product['sku']) == 0) { - continue; - } - $sku[]= $product['sku']; + $this->setError("Невірна відповідь"); + \App\Helper::log($json); + return; } + if ($data['error'] == "") { - $cat = $this->filter->searchcat->getValue(); - $where = "disabled <> 1 "; - if ($cat > 0) { - $where .= " and cat_id=" . $cat; - } - - foreach (Item::findYield($where, "itemname") as $item) { - if (strlen($item->item_code) == 0) { - continue; + $cat = $this->filter->searchcat->getValue(); + $where = "disabled <> 1 "; + if ($cat > 0) { + $where .= " and cat_id=" . $cat; } - if (in_array($item->item_code, $sku)) { - continue; - } //уже в магазине - $item->qty = $item->getQuantity(); + + foreach (Item::findYield($where, "itemname") as $item) { + if (strlen($item->item_code) == 0) { + continue; + } + if (in_array($item->item_code, $data['articles'])) { + continue; + } //уже в магазине + $item->qty = $item->getQuantity(); - if (strlen($item->qty) == 0) { - $item->qty = 0; + if (strlen($item->qty) == 0) { + $item->qty = 0; + } + $this->_items[] = $item; } - $this->_items[] = $item; - } - $this->exportform->newitemlist->Reload(); - //$this->exportform->ecat->setValue(0); + $this->exportform->newitemlist->Reload(); + $this->exportform->ecat->setValue(0); + } else { + $data['error'] = str_replace("'", "`", $data['error']) ; + $this->setErrorTopPage($data['error']); + } } public function itemOnRow($row) { @@ -129,7 +203,7 @@ public function itemOnRow($row) { public function exportOnSubmit($sender) { $modules = System::getOptions("modules"); -// $cat = $this->exportform->ecat->getValue(); + $cat = $this->exportform->ecat->getValue(); $elist = array(); foreach ($this->_items as $item) { @@ -138,8 +212,8 @@ public function exportOnSubmit($sender) { } $elist[] = array('name' => $item->itemname, 'sku' => $item->item_code, - 'quantity_in_stock' => \App\Helper::fqty($item->qty), - 'price' => \App\Helper::fa($item->getPrice($modules['pupricetype'])) + 'quantity' => \App\Helper::fqty($item->qty), + 'price' => $item->getPrice($modules['ocpricetype']) ); } if (count($elist) == 0) { @@ -147,17 +221,30 @@ public function exportOnSubmit($sender) { $this->setError('Не обрано товар'); return; } - $data = json_encode($elist, JSON_UNESCAPED_UNICODE); + $data = json_encode($elist); + $fields = array( + 'data' => $data, + 'cat' => $cat + ); + $url = $modules['ocsite'] . '/index.php?route=api/zstore/addproducts&' . System::getSession()->octoken; + if($modules['ocv4']==1) { + $url = $modules['ocsite'] . '/index.php?route=api/zstore.addproducts&' . System::getSession()->octoken; + } - try { - $data = Helper::make_request("POST", "/api/v1/products/import_file", $data); - } catch(\Exception $ee) { - System::setErrorMsg($ee->getMessage()); + $json = Helper::do_curl_request($url, $fields); + if ($json === false) { return; } + $data = json_decode($json, true); + + if ($data['error'] != "") { + $data['error'] = str_replace("'", "`", $data['error']) ; + $this->setErrorTopPage($data['error']); + return; + } $this->setSuccess("Експортовано ".count($elist)." товарів"); //обновляем таблицу @@ -165,9 +252,8 @@ public function exportOnSubmit($sender) { } public function onUpdateQty($sender) { - - $cat = $this->upd->updcat->getValue(); $modules = System::getOptions("modules"); + $cat = $this->upd->updcat->getValue(); $elist = array(); @@ -177,64 +263,31 @@ public function onUpdateQty($sender) { } $qty = $item->getQuantity(); - $elist[$item->item_code] = H::fqty($qty); + $elist[$item->item_code] = round($qty); } + $data = json_encode($elist); - $products = array(); - try { - $last_id=0; - while(true) { - $data = Helper::make_request("GET", "/api/v1/products/list?last_id=".$last_id, null); - if(count($data['products'])==0) { - break; - } - foreach ($data['products'] as $product) { - $products[]=$product; - $last_id = $product['id'] ; - } - } - - - - - } catch(\Exception $ee) { - System::setErrorMsg($ee->getMessage()); - return; + $fields = array( + 'data' => $data + ); + $url = $modules['ocsite'] . '/index.php?route=api/zstore/updatequantity&' . System::getSession()->octoken; + if($modules['ocv4']==1) { + $url = $modules['ocsite'] . '/index.php?route=api/zstore.updatequantity&' . System::getSession()->octoken; } - $sku = array(); - foreach ($products as $product) { - - if (strlen($product['sku']) == 0) { - continue; - } - $sku[$product['sku']]= $product['id']; - } - - $list = array(); - foreach ($elist as $code=>$qty) { - - if($sku[$code]>0) { - $list[] = array('sku' => $sku[$code], - - 'quantity_in_stock' =>$elist[$code] - - ); - } + $json = Helper::do_curl_request($url, $fields); + if ($json === false) { + return; } + $data = json_decode($json, true); - $data = json_encode($list, JSON_UNESCAPED_UNICODE); - + if ($data['error'] != "") { + $data['error'] = str_replace("'", "`", $data['error']) ; - - try { - $data = Helper::make_request("POST", "/api/v1/products/edit", $data); - } catch(\Exception $ee) { - System::setErrorMsg($ee->getMessage()); + $this->setErrorTopPage($data['error']); return; } - - $this->setSuccess('Оновлено'); + $this->setSuccess('Оновлено'); } public function onUpdatePrice($sender) { @@ -247,177 +300,163 @@ public function onUpdatePrice($sender) { if (strlen($item->item_code) == 0) { continue; } - - $elist[$item->item_code] = \App\Helper::fa($item->getPrice($modules['pupricetype'])); + $elist[$item->item_code] = $item->getPrice($modules['ocpricetype']); } - $products = array(); - try { - $last_id=0; - while(true) { - $data = Helper::make_request("GET", "/api/v1/products/list?last_id=".$last_id, null); - if(count($data['products'])==0) { - break; - } - foreach ($data['products'] as $product) { - $products[]=$product; - $last_id = $product['id'] ; - } - } - - - + $data = json_encode($elist); - } catch(\Exception $ee) { - System::setErrorMsg($ee->getMessage()); - return; + $fields = array( + 'data' => $data + ); + $url = $modules['ocsite'] . '/index.php?route=api/zstore/updateprice&' . System::getSession()->octoken; + if($modules['ocv4']==1) { + $url = $modules['ocsite'] . '/index.php?route=api/zstore.updateprice&' . System::getSession()->octoken; } - $sku = array(); - foreach ($products as $product) { - if (strlen($product['sku']) == 0) { - continue; - } - $sku[$product['sku']]= $product['id']; - } - - $list = array(); - foreach ($elist as $code=>$price) { - - if($sku[$code]>0) { - $list[] = array('sku' => $sku[$code], - - - 'price' =>$price - - ); - } + $json = Helper::do_curl_request($url, $fields); + if ($json === false) { + return; } + $data = json_decode($json, true); - $data = json_encode($list, JSON_UNESCAPED_UNICODE); - + if ($data['error'] != "") { + $data['error'] = str_replace("'", "`", $data['error']) ; - - try { - $data = Helper::make_request("POST", "/api/v1/products/edit", $data); - } catch(\Exception $ee) { - System::setErrorMsg($ee->getMessage()); + $this->setErrorTopPage($data['error']); return; } - - $this->setSuccess('Оновлено'); + $this->setSuccess('Оновлено'); } public function importOnSubmit($sender) { $modules = System::getOptions("modules"); $common = System::getOptions("common"); - - - $elist = array(); - $products = array(); - try { - $last_id=0; - while(true) { - $data = Helper::make_request("GET", "/api/v1/products/list?last_id=".$last_id, null); - if(count($data['products'])==0) { - break; - } - foreach ($data['products'] as $product) { - $products[]=$product; - $last_id = $product['id'] ; - } - } - - - - - } catch(\Exception $ee) { - System::setErrorMsg($ee->getMessage()); + $conn = \ZDB\DB::getConnect(); + + if(count($this->_pages)==0){ + $this->setError('Не оновллені категорії') ; return; } - - - // $this->setInfo($json); + + + $token= \App\Modules\HR\Helper::connect(); + if(strlen($token)==0) { + return; + } + $i = 0; - foreach ($products as $product) { - if (strlen($product['sku']) == 0) { - continue; + $page = 0; + while(true) { + + + try { + + $body=[]; + $body['token'] =$token; + $body['expr'] =[]; + $body['offset'] = $page * 100 ; + $body['limit'] = 100; + + $ret = \App\Modules\HR\Helper::make_request("POST", "/api/catalog/export", json_encode($body, JSON_UNESCAPED_UNICODE)); + + } catch(\Exception $ee) { + $this->setErrorTopPage($ee->getMessage()); + return; } - $cnt = Item::findCnt("item_code=" . Item::qstr($product['sku'])); - if ($cnt > 0) { - continue; - } //уже есть с таким артикулом + $page++; - $product['name'] = str_replace('"', '"', $product['name']); - $item = new Item(); - $item->item_code = $product['sku']; - $item->itemname = $product['name']; - // $item->description = $product['description']; - - if ($modules['pupricetype'] == 'price1') { - $item->price1 = $product['price']; - } - if ($modules['pupricetype'] == 'price2') { - $item->price2 = $product['price']; - } - if ($modules['pupricetype'] == 'price3') { - $item->price3 = $product['price']; - } - if ($modules['pupricetype'] == 'price4') { - $item->price4 = $product['price']; + $data= $ret['products'] ; + + $c = count($data); + if ($c == 0) { + break; } - if ($modules['pupricetype'] == 'price5') { - $item->price5 = $product['price']; - } - - - if ($common['useimages'] == 1) { - $im = $product['main_image']; - $im = @file_get_contents($im); - if (strlen($im) > 0) { - $imagedata = getimagesizefromstring($im); - $image = new \App\Entity\Image(); - $image->content = $im; - $image->mime = $imagedata['mime']; - $conn = \ZDB\DB::getConnect(); - if($conn->dataProvider=='postgres') { - $image->thumb = pg_escape_bytea($image->thumb); - $image->content = pg_escape_bytea($image->content); - - } + foreach ($data as $product) { - $image->save(); - $item->image_id = $image->image_id; + if (strlen($product['article']) == 0) { + continue; } - } - - $cat_name =trim($product['group']['name']); - if($sender->createcat->isChecked() && strlen($cat_name)>0) { - - - $cat_name = str_replace(' ', '', $cat_name) ; - if(strpos($cat_name, '>')>0) { - $ar = explode('>', $cat_name) ; - $cat_name = trim($ar[count($ar)-1]); - + if (intval($product['price']) == 0) { + continue; //категория + } + $cnt = Item::findCnt("item_code=" . Item::qstr($product['article'])); + if ($cnt > 0) { + continue; + } //уже есть с таким артикулом + + $product->name = str_replace('"', '"', $product['article']); + $item = new Item(); + $item->item_code = $product['article'] ; + $item->itemname = $product['title']['ua'] ?? ''; + if($item->itemname =='') { + $item->itemname = $product['title']['ru'] ?? ''; + } + if($item->itemname =='') { + continue; + } + $item->description = $product['short_description']['ua'] ?? ''; + if($item->description =='') { + $item->description = $product['short_description']['ru'] ?? ''; } - $cat = \App\Entity\Category::getFirst("cat_name=" . \App\Entity\Category::qstr($cat_name)) ; - if($cat == null) { - $cat = new \App\Entity\Category(); - $cat->cat_name = $cat_name; - $cat->save(); + if ($modules['hrpricetype'] == 'price1') { + $item->price1 = H::fa($product['price']); + } + if ($modules['hrpricetype'] == 'price2') { + $item->price2 = H::fa($product['price']);; + } + if ($modules['hrpricetype'] == 'price3') { + $item->price3 = H::fa($product['price']);; + } + if ($modules['hrpricetype'] == 'price4') { + $item->price4 = H::fa($product['price']);; + } + if ($modules['hrcpricetype'] == 'price5') { + $item->price5 = H::fa($product['price']);; + } + $item->manufacturer = $product['brand']['value']['ua'] ?? ''; + if($item->manufacturer =='') { + $item->manufacturer = $product['brand']['value']['ru'] ?? ''; + } + + $item->uktz = $product['uktzed'] ; + $item->url = $product['link'] ; + $cat_id= $product['parent']['id']??0; + if(isset($this->_origpages[$cat_id])) { + $item->cat_id= $this->_origpages[$cat_id] ; + } + + + + if ($common['useimages'] == 1) { + foreach ($product['images'] as $im) { + + $im = @file_get_contents($im); + if (strlen($im) > 0) { + $imagedata = getimagesizefromstring($im); + $image = new \App\Entity\Image(); + $image->content = $im; + $image->mime = $imagedata['mime']; + + if($conn->dataProvider=='postgres') { + $image->thumb = pg_escape_bytea($image->thumb); + $image->content = pg_escape_bytea($image->content); + + } + $image->save(); + $item->image_id = $image->image_id; + break; + } + } } - $item->cat_id=$cat->cat_id; + + $item->save(); + } - - - $item->save(); - $i++; } $this->setSuccess("Завантажено {$i} товарів"); diff --git a/www/app/pages/reference/categorylist.php b/www/app/pages/reference/categorylist.php index 6ce1b0466..ba8af9abf 100644 --- a/www/app/pages/reference/categorylist.php +++ b/www/app/pages/reference/categorylist.php @@ -169,6 +169,7 @@ public function deleteOnClick($sender) { Category::delete($cat_id); $this->Reload(); + $this->resetURL() ; } public function editOnClick($sender) { diff --git a/www/templates/modules/hr/items.html b/www/templates/modules/hr/items.html index 07132d471..f463015bd 100644 --- a/www/templates/modules/hr/items.html +++ b/www/templates/modules/hr/items.html @@ -1,15 +1,15 @@ -
- - {{#hideblock}}
- -

Експорт товарів в магазин

+ +

Експорт товарів в магазин

   Спецсимволи (типу & ' " `) - в назвi або описi може викликати проблеми з вигрузкою - - - {{/hideblock}}

Оновлення цін та кількості

@@ -91,21 +96,18 @@

Оновлення цін та кількості

Iмпорт товарів з магазину

@@ -113,15 +115,22 @@

Iмпорт товарів з магазину

function check_updateqty() { - document.getElementById('dialogwait').showModal() + document.getElementById('dialogwait').showModal() } function check_updateprice() { + document.getElementById('dialogwait').showModal() + } + + function check_getitems() { + document.getElementById('dialogwait').showModal() } + function check_checkconn() { - + document.getElementById('dialogwait').showModal() + } function chclick() { var ch = $("#chall").prop('checked'); From 48e343718b70969b55941bc6c43913314599fe79 Mon Sep 17 00:00:00 2001 From: "leon.mbs@gmail.com" Date: Wed, 20 Dec 2023 23:19:18 +0200 Subject: [PATCH 04/13] qty --- www/app/modules/hr/items.php | 114 +++++++++++++++++++++++++++-------- 1 file changed, 89 insertions(+), 25 deletions(-) diff --git a/www/app/modules/hr/items.php b/www/app/modules/hr/items.php index 23eb5ad7d..3f014dc30 100644 --- a/www/app/modules/hr/items.php +++ b/www/app/modules/hr/items.php @@ -9,6 +9,7 @@ use Zippy\Binding\PropertyBinding as Prop; use Zippy\Html\DataList\ArrayDataSource; use Zippy\Html\DataList\DataView; +use Zippy\Html\Form\SubmitButton; use Zippy\Html\Form\CheckBox; use Zippy\Html\Form\DropDownChoice; use Zippy\Html\Form\Form; @@ -56,8 +57,9 @@ public function __construct() { - $this->add(new Form('importform'))->onSubmit($this, 'importOnSubmit'); - + $this->add(new Form('importform')) ; + $this->importform->add(new SubmitButton('getitems'))->onClick($this, 'importOnSubmit'); + } @@ -254,7 +256,13 @@ public function exportOnSubmit($sender) { public function onUpdateQty($sender) { $modules = System::getOptions("modules"); $cat = $this->upd->updcat->getValue(); - + + + $articles = $this->getArticles(); + + + $body=[]; + $body['products']=[]; $elist = array(); foreach (Item::findYield("disabled <> 1 ". ($cat>0 ? " and cat_id=".$cat : "")) as $item) { @@ -262,32 +270,33 @@ public function onUpdateQty($sender) { continue; } + if(in_array($item->item_code,$articles)===false) { + continue; + } + $qty = $item->getQuantity(); + $qty = 33; $elist[$item->item_code] = round($qty); + $body['products'][]=array( + 'article'=>$item->item_code, + 'warehouse'=>"office", + 'quantity'=>$qty, + ); + } - $data = json_encode($elist); - - $fields = array( - 'data' => $data - ); - $url = $modules['ocsite'] . '/index.php?route=api/zstore/updatequantity&' . System::getSession()->octoken; - if($modules['ocv4']==1) { - $url = $modules['ocsite'] . '/index.php?route=api/zstore.updatequantity&' . System::getSession()->octoken; - } - $json = Helper::do_curl_request($url, $fields); - if ($json === false) { + + $token= \App\Modules\HR\Helper::connect(); + if(strlen($token)==0) { return; } - $data = json_decode($json, true); - - if ($data['error'] != "") { - $data['error'] = str_replace("'", "`", $data['error']) ; + + $body['token'] =$token; + - $this->setErrorTopPage($data['error']); - return; - } - $this->setSuccess('Оновлено'); + $ret = \App\Modules\HR\Helper::make_request("POST", "/api/catalog/importResidues", json_encode($body, JSON_UNESCAPED_UNICODE)); + + $this->setSuccess('Оновлено'); } public function onUpdatePrice($sender) { @@ -377,9 +386,7 @@ public function importOnSubmit($sender) { if (strlen($product['article']) == 0) { continue; } - if (intval($product['price']) == 0) { - continue; //категория - } + $cnt = Item::findCnt("item_code=" . Item::qstr($product['article'])); if ($cnt > 0) { continue; @@ -387,6 +394,9 @@ public function importOnSubmit($sender) { $product->name = str_replace('"', '"', $product['article']); $item = new Item(); + $item->item_type=Item::TYPE_TOVAR ; + + $item->item_code = $product['article'] ; $item->itemname = $product['title']['ua'] ?? ''; if($item->itemname =='') { @@ -461,5 +471,59 @@ public function importOnSubmit($sender) { $this->setSuccess("Завантажено {$i} товарів"); } + + private function getArticles() { + $modules = System::getOptions("modules"); + $common = System::getOptions("common"); + + + $token= \App\Modules\HR\Helper::connect(); + if(strlen($token)==0) { + return []; + } + $r=[]; + $i = 0; + + $page = 0; + while(true) { + + + try { + + $body=[]; + $body['token'] =$token; + $body['expr'] =[]; + $body['offset'] = $page * 100 ; + $body['limit'] = 100; + + $ret = \App\Modules\HR\Helper::make_request("POST", "/api/catalog/export", json_encode($body, JSON_UNESCAPED_UNICODE)); + + } catch(\Exception $ee) { + $this->setErrorTopPage($ee->getMessage()); + return; + } + $page++; + + $data= $ret['products'] ; + + $c = count($data); + if ($c == 0) { + break; + } + foreach ($data as $product) { + + if (strlen($product['article']) == 0) { + continue; + } + + $r[] = $product['article'] ; + + + + } + } + + return $r; + } } From 0b6ddac2cb367452df5bdd974d6013677e8540b7 Mon Sep 17 00:00:00 2001 From: "leon.mbs@gmail.com" Date: Thu, 21 Dec 2023 14:21:18 +0200 Subject: [PATCH 05/13] items --- www/app/modules/hr/helper.php | 2 +- www/app/modules/hr/items.php | 154 +++++++++++++++------------- www/templates/modules/hr/items.html | 6 +- 3 files changed, 84 insertions(+), 78 deletions(-) diff --git a/www/app/modules/hr/helper.php b/www/app/modules/hr/helper.php index 5ba6f421a..ebeb659e5 100644 --- a/www/app/modules/hr/helper.php +++ b/www/app/modules/hr/helper.php @@ -75,7 +75,7 @@ public static function make_request($method, $url, $body='') { curl_close($ch); $ret = json_decode($result, true) ; - if (strlen($ret['status']=='error') ) { + if (strlen($ret['status']=='ERROR') ) { throw new \Exception($ret['response']['message']); } diff --git a/www/app/modules/hr/items.php b/www/app/modules/hr/items.php index 3f014dc30..27a4898a7 100644 --- a/www/app/modules/hr/items.php +++ b/www/app/modules/hr/items.php @@ -44,7 +44,7 @@ public function __construct() { $this->exportform->add(new DataView('newitemlist', new ArrayDataSource(new Prop($this, '_items')), $this, 'itemOnRow')); $this->exportform->newitemlist->setPageSize(H::getPG()); $this->exportform->add(new \Zippy\Html\DataList\Paginator('pag', $this->exportform->newitemlist)); - $this->exportform->add(new DropDownChoice('ecat', $cats, 0)); + $this->exportform->add(new DropDownChoice('ecat', [], 0)); $this->add(new Form('upd')); $this->upd->add(new DropDownChoice('updcat', \App\Entity\Category::getList(), 0)); @@ -133,6 +133,8 @@ public function onCheck($sender) { } } + + $this->exportform->ecat->setOptionList($pages); } catch(\Exception $ee) { $this->setErrorTopPage($ee->getMessage()); @@ -144,22 +146,10 @@ public function onCheck($sender) { public function filterOnSubmit($sender) { $this->_items = array(); $modules = System::getOptions("modules"); - $url = $modules['ocsite'] . '/index.php?route=api/zstore/articles&' . System::getSession()->octoken; - if($modules['ocv4']==1) { - $url = $modules['ocsite'] . '/index.php?route=api/zstore.articles&' . System::getSession()->octoken; - } - $json = Helper::do_curl_request($url); - if ($json === false) { - return; - } - $data = json_decode($json, true); - if (!isset($data)) { - - $this->setError("Невірна відповідь"); - \App\Helper::log($json); - return; - } - if ($data['error'] == "") { + + $articles=$this->getArticles(); + + if (count($articles)>0) { $cat = $this->filter->searchcat->getValue(); $where = "disabled <> 1 "; @@ -171,7 +161,7 @@ public function filterOnSubmit($sender) { if (strlen($item->item_code) == 0) { continue; } - if (in_array($item->item_code, $data['articles'])) { + if (in_array($item->item_code, $articles)) { continue; } //уже в магазине $item->qty = $item->getQuantity(); @@ -207,47 +197,56 @@ public function exportOnSubmit($sender) { $modules = System::getOptions("modules"); $cat = $this->exportform->ecat->getValue(); - $elist = array(); + if($cat==0) { + return; + } + + $body=[]; + $body['products']=[]; + foreach ($this->_items as $item) { if ($item->ch == false) { continue; } - $elist[] = array('name' => $item->itemname, - 'sku' => $item->item_code, - 'quantity' => \App\Helper::fqty($item->qty), - 'price' => $item->getPrice($modules['ocpricetype']) - ); - } - if (count($elist) == 0) { - - $this->setError('Не обрано товар'); - return; - } - $data = json_encode($elist); - - $fields = array( - 'data' => $data, - 'cat' => $cat - ); + + $price = $item->getPrice($modules['hrpricetype']); + + $p=array( + 'article'=>$item->item_code, + 'title'=>$item->itemname, + 'short_description'=>$item->description ?? '', + 'brand'=>$item->manufacturer ?? '', - $url = $modules['ocsite'] . '/index.php?route=api/zstore/addproducts&' . System::getSession()->octoken; - if($modules['ocv4']==1) { - $url = $modules['ocsite'] . '/index.php?route=api/zstore.addproducts&' . System::getSession()->octoken; + 'price'=>number_format($price, 2, '.', ''), + ); + + $p['parent'] =array('id'=>intval($cat)); + + $body['products'][] = $p; + } + if (count($body['products']) == 0) { - $json = Helper::do_curl_request($url, $fields); - if ($json === false) { + $this->setError('Не обрано товар'); return; } - $data = json_decode($json, true); - if ($data['error'] != "") { - $data['error'] = str_replace("'", "`", $data['error']) ; + try{ + + $token= \App\Modules\HR\Helper::connect(); + if(strlen($token)==0) { + return; + } + + $body['token'] =$token; - $this->setErrorTopPage($data['error']); - return; + $ret = \App\Modules\HR\Helper::make_request("POST", "/api/catalog/import/", json_encode($body, JSON_UNESCAPED_UNICODE)); + + } catch(\Exception $ee) { + $this->setErrorTopPage($ee->getMessage()); + return; } - $this->setSuccess("Експортовано ".count($elist)." товарів"); + $this->setSuccess("Експортовано ".count( $body['products'])." товарів"); //обновляем таблицу $this->filterOnSubmit(null); @@ -263,7 +262,7 @@ public function onUpdateQty($sender) { $body=[]; $body['products']=[]; - $elist = array(); + foreach (Item::findYield("disabled <> 1 ". ($cat>0 ? " and cat_id=".$cat : "")) as $item) { if (strlen($item->item_code) == 0) { @@ -274,9 +273,9 @@ public function onUpdateQty($sender) { continue; } - $qty = $item->getQuantity(); - $qty = 33; - $elist[$item->item_code] = round($qty); + $price = $item->getPrice($modules['hrpricetype']); + + $body['products'][]=array( 'article'=>$item->item_code, 'warehouse'=>"office", @@ -302,39 +301,46 @@ public function onUpdateQty($sender) { public function onUpdatePrice($sender) { $modules = System::getOptions("modules"); $cat = $this->upd->updcat->getValue(); - - $elist = array(); + + + $articles = $this->getArticles(); + + + $body=[]; + $body['products']=[]; + foreach (Item::findYield("disabled <> 1 ". ($cat>0 ? " and cat_id=".$cat : "")) as $item) { if (strlen($item->item_code) == 0) { continue; } - $elist[$item->item_code] = $item->getPrice($modules['ocpricetype']); - } - - $data = json_encode($elist); - $fields = array( - 'data' => $data - ); - $url = $modules['ocsite'] . '/index.php?route=api/zstore/updateprice&' . System::getSession()->octoken; - if($modules['ocv4']==1) { - $url = $modules['ocsite'] . '/index.php?route=api/zstore.updateprice&' . System::getSession()->octoken; + if(in_array($item->item_code,$articles)===false) { + continue; + } + + $price = $item->getPrice($modules['hrpricetype']); + + $body['products'][]=array( + 'article'=>$item->item_code, + 'price'=>number_format($price, 2, '.', ''), + ); + + } - $json = Helper::do_curl_request($url, $fields); - if ($json === false) { + + $token= \App\Modules\HR\Helper::connect(); + if(strlen($token)==0) { return; } - $data = json_decode($json, true); - - if ($data['error'] != "") { - $data['error'] = str_replace("'", "`", $data['error']) ; + + $body['token'] =$token; + - $this->setErrorTopPage($data['error']); - return; - } - $this->setSuccess('Оновлено'); + $ret = \App\Modules\HR\Helper::make_request("POST", "/api/catalog/import/", json_encode($body, JSON_UNESCAPED_UNICODE)); + + $this->setSuccess('Оновлено'); } public function importOnSubmit($sender) { @@ -471,7 +477,7 @@ public function importOnSubmit($sender) { $this->setSuccess("Завантажено {$i} товарів"); } - + //список артикулов в магазе private function getArticles() { $modules = System::getOptions("modules"); $common = System::getOptions("common"); diff --git a/www/templates/modules/hr/items.html b/www/templates/modules/hr/items.html index f463015bd..3bb3a5ae7 100644 --- a/www/templates/modules/hr/items.html +++ b/www/templates/modules/hr/items.html @@ -70,7 +70,7 @@

Експорт товарів в магазин

-

Оновлення цін та кількості

+

Оновлення кількості

From 95451949f9f5badda447ce52f2bd1c17930e8c7d Mon Sep 17 00:00:00 2001 From: "leon.mbs@gmail.com" Date: Thu, 21 Dec 2023 19:09:34 +0200 Subject: [PATCH 06/13] =?UTF-8?q?=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- www/app/modules/hr/orders.php | 205 ++++++++++++++++++--------- www/app/modules/pu/orders.php | 2 +- www/app/util.php | 3 + www/templates/modules/hr/orders.html | 26 ++-- www/templates/modules/pu/orders.html | 9 +- 5 files changed, 167 insertions(+), 78 deletions(-) diff --git a/www/app/modules/hr/orders.php b/www/app/modules/hr/orders.php index 5e6ee9401..f8d712545 100644 --- a/www/app/modules/hr/orders.php +++ b/www/app/modules/hr/orders.php @@ -21,7 +21,7 @@ class Orders extends \App\Pages\Base { public $_neworders = array(); public $_eorders = array(); - + public function __construct() { parent::__construct(); @@ -34,10 +34,9 @@ public function __construct() { $modules = System::getOptions("modules"); - $statuses = Helper::connect() ; $this->add(new Form('filter'))->onSubmit($this, 'filterOnSubmit'); - $this->filter->add(new DropDownChoice('status', $statuses, 'pending')); + $this->filter->add(new DropDownChoice('status', [], 'pending')); $this->add(new DataView('neworderslist', new ArrayDataSource(new Prop($this, '_neworders')), $this, 'noOnRow')); @@ -46,8 +45,9 @@ public function __construct() { $this->add(new ClickLink('refreshbtn'))->onClick($this, 'onRefresh'); $this->add(new Form('updateform'))->onSubmit($this, 'exportOnSubmit'); $this->updateform->add(new DataView('orderslist', new ArrayDataSource(new Prop($this, '_eorders')), $this, 'expRow')); - $this->updateform->add(new DropDownChoice('estatus', $statuses, 'delivered')); + $this->updateform->add(new DropDownChoice('estatus', [], 'delivered')); + $this->add(new ClickLink('checkconn'))->onClick($this, 'onCheck'); } @@ -55,14 +55,26 @@ public function __construct() { public function filterOnSubmit($sender) { $modules = System::getOptions("modules"); - $client = \App\Modules\WC\Helper::getClient(); - + $st = $this->filter->status->getValue(); + $this->_neworders = array(); - + $token= \App\Modules\HR\Helper::connect(); + if(strlen($token)==0) { + return; + } + + + try { - $data = Helper::make_request("GET", "/api/v1/orders/list?status=". $this->filter->status->getValue(), null); - + $body=[]; + $body['token'] =$token; + $body['status'] =$st; + + + $ret = \App\Modules\HR\Helper::make_request("POST", "/api/orders/get/", json_encode($body, JSON_UNESCAPED_UNICODE)); + + } catch(\Exception $ee) { $this->setErrorTopPage($ee->getMessage()); return; @@ -71,9 +83,9 @@ public function filterOnSubmit($sender) { $conn = \ZDB\DB::getConnect(); - foreach ($data['orders'] as $puorder) { + foreach ($ret['orders'] as $hrorder) { - $cnt = $conn->getOne("select count(*) from documents_view where meta_name='Order' and content like '%{$puorder['id']}%' ") ; + $cnt = $conn->getOne("select count(*) from documents_view where meta_name='Order' and content like '%{$hrorder['order_id']}%' ") ; if (intval($cnt) > 0) { //уже импортирован @@ -82,25 +94,26 @@ public function filterOnSubmit($sender) { $neworder = Document::create('Order'); - + $amount=0; //товары $j=0; $itlist = array(); - foreach ($puorder['products'] as $product) { + foreach ($hrorder['products'] as $product) { //ищем по артикулу - if (strlen($product['sku']) == 0) { + if (strlen($product['article']) == 0) { continue; } - $code = Item::qstr($product['sku']); + $code = Item::qstr($product['article']); $tovar = Item::getFirst('item_code=' . $code); if ($tovar == null) { - $this->setWarn("Не знайдено артикул товара {$product['name']} в замовленні номер " . $puorder['order_id']); + $this->setWarn("Не знайдено артикул товара {$product['article']} в замовленні номер " . $hrorder['order_id']); continue; } $tovar->quantity = H::fqty($product['quantity']); $tovar->price = H::fa($product['price']); + $amount += ($product['price']*$product['quantity']); $j++; $tovar->rowid = $j; @@ -113,42 +126,45 @@ public function filterOnSubmit($sender) { $neworder->packDetails('detaildata', $itlist); $neworder->headerdata['pricetype'] = 'price1'; - $neworder->headerdata['cemail'] = $puorder['email']; - $neworder->headerdata['cname'] = $puorder['client_first_name'] . ' ' . $puorder['client_last_name']; - $neworder->headerdata['cphone'] = $puorder['phone'] ; - $neworder->headerdata['puorder'] = $puorder['id']; - $neworder->headerdata['outnumber'] = $puorder['id']; - $neworder->headerdata['puorderback'] = 0; - $neworder->headerdata['salesource'] = $modules['pusalesource']; + $neworder->headerdata['cemail'] = $hrorder['delivery_email']; + $neworder->headerdata['cname'] = $hrorder['delivery_name'] ; + $neworder->headerdata['cphone'] = $hrorder['delivery_phone'] ; + $neworder->headerdata['hrorder'] = $hrorder['order_id']; + $neworder->headerdata['outnumber'] = $hrorder['order_id']; + $neworder->headerdata['hrorderback'] = 0; + $neworder->headerdata['salesource'] = $modules['salesource']; - $neworder->headerdata['puclient'] = $puorder['client_first_name'] . ' ' . $puorder['client_last_name']; + $neworder->headerdata['hrclient'] = $hrorder['delivery_name'] ; - $neworder->amount = H::fa($puorder['price']); - $neworder->payamount = H::fa($puorder['full_price']); + $neworder->amount = H::fa($amount); + $neworder->payamount = H::fa($amount); - $neworder->document_date = time(); - $neworder->notes = "PU номер:{$puorder['id']};"; - $neworder->notes .= " Клієнт:" .$puorder['client_first_name'] . ' ' . $puorder['client_last_name'].';'; - if (strlen($puorder['email']) > 0) { - $neworder->notes .= " Email:" . $puorder['email'] . ";"; + $neworder->document_date = strtotime($hrorder['stat_created']); + if($neworder->document_date==0) { + $neworder->document_date = time() ; + } + $neworder->notes = "HR номер:{$hrorder['order_id']};"; + $neworder->notes .= " Клієнт:" .$hrorder['delivery_name'] ; + if (strlen($hrorder['delivery_email']) > 0) { + $neworder->notes .= " Email:" . $hrorder['delivery_email'] . ";"; } - if (strlen($puorder['phone']) > 0) { - $neworder->notes .= " Тел:" . str_replace('+', '', $puorder['phone']). ";"; + if (strlen($hrorder['delivery_phone']) > 0) { + $neworder->notes .= " Тел:" . str_replace('+', '', $hrorder['delivery_phone']). ";"; } - if (strlen($puorder['delivery_option']['name']) > 0) { - $neworder->notes .= " Доставка:" . $puorder['delivery_option']['name'] . ";"; + if (strlen($hrorder['delivery_option']['name']) > 0) { + $neworder->notes .= " Доставка:" . ($hrorder['delivery_type']['title']??'') . ";"; } - if (strlen($puorder['delivery_address']) > 0) { - $neworder->notes .= " Адреса:" . $puorder['delivery_address'] . ";"; + if (strlen($hrorder['delivery_address']) > 0) { + $neworder->notes .= " Адреса:" . $hrorder['delivery_city'] .' '. $hrorder['delivery_address']. ";"; } - if (strlen($puorder['client_notes']) > 0) { - $neworder->notes .= " Комментар:" . $puorder['client_notes'] . ";"; + if (strlen($hrorder['comment']) > 0) { + $neworder->notes .= " Комментар:" . $hrorder['comment'] . ";"; } - $this->_neworders[$puorder['id']] = $neworder; + $this->_neworders[$hrorder['order_id']] = $neworder; } $this->neworderslist->Reload(); @@ -157,11 +173,11 @@ public function filterOnSubmit($sender) { public function noOnRow($row) { $order = $row->getDataItem(); - $row->add(new Label('number', $order->headerdata['puorder'])); - $row->add(new Label('customer', $order->headerdata['puclient'])); + $row->add(new Label('number', $order->headerdata['hrorder'])); + $row->add(new Label('customer', $order->headerdata['hrclient'])); $row->add(new Label('amount', round($order->amount))); $row->add(new Label('comment', $order->notes)); - $row->add(new Label('date', \App\Helper::fdt(strtotime($order->document_date)))); + $row->add(new Label('date', \App\Helper::fdt($order->document_date))); } public function onImport($sender) { @@ -170,10 +186,10 @@ public function onImport($sender) { foreach ($this->_neworders as $shoporder) { $shoporder->document_number = $shoporder->nextNumber(); if (strlen($shoporder->document_number) == 0) { - $shoporder->document_number = 'PU00001'; + $shoporder->document_number = 'HR-00001'; } - if ( $modules['puinsertcust'] == 1) { + if ( $modules['hrinsertcust'] == 1) { $phone = \App\Util::handlePhone($shoporder->headerdata['cphone'] ) ; $cust = Customer::getByPhone($phone); if ($cust == null) { @@ -181,13 +197,13 @@ public function onImport($sender) { } if ($cust == null &&strlen($shoporder->headerdata['cname']) >0 && ( strlen($phone) >0 || strlen($shoporder->headerdata['cemail'])>0 ) ) { $cust = new Customer(); - $cust->customer_name = $shoporder->headerdata['cname']; + $cust->customer_name = $shoporder->headerdata['cname']; $cust->phone = $phone; $cust->type = Customer::TYPE_BAYER; $cust->email = $shoporder->headerdata['cemail']; - $cust->comment = "Клiєнт Prom UA"; + $cust->comment = "Клiєнт Хорошоп"; $cust->save(); } if($cust != null) { @@ -214,7 +230,7 @@ public function onImport($sender) { public function onRefresh($sender) { - $this->_eorders = Document::find("meta_name='Order' and content like '%0%' and state <> " . Document::STATE_NEW); + $this->_eorders = Document::find("meta_name='Order' and content like '%0%' and state <> " . Document::STATE_NEW); $this->updateform->orderslist->Reload(); } @@ -222,17 +238,19 @@ public function expRow($row) { $order = $row->getDataItem(); $row->add(new CheckBox('ch', new Prop($order, 'ch'))); $row->add(new Label('number2', $order->document_number)); - $row->add(new Label('number3', $order->headerdata['puorder'])); + $row->add(new Label('number3', $order->headerdata['hrorder'])); $row->add(new Label('date2', \App\Helper::fdt($order->document_date))); $row->add(new Label('amount2', $order->amount)); - $row->add(new Label('customer2', $order->headerdata['puclient'])); + $row->add(new Label('customer2', $order->headerdata['hrclient'])); $row->add(new Label('state', Document::getStateName($order->state))); } public function exportOnSubmit($sender) { $modules = System::getOptions("modules"); $st = $this->updateform->estatus->getValue(); - + if($st==0){ + return; + } $elist = array(); foreach ($this->_eorders as $order) { @@ -246,34 +264,85 @@ public function exportOnSubmit($sender) { return; } - $fields = array( - 'status' => $st - ); - foreach ($elist as $order) { + $token= \App\Modules\HR\Helper::connect(); + if(strlen($token)==0) { + return; + } + + $body=[]; + $body['token'] =$token; + $body['orders'] =[]; + + $conn = \ZDB\DB::getConnect(); + $conn->BeginTrans(); + try { + + foreach ($elist as $order) { + + $body['orders'][] = array('order_id'=>$order->headerdata['hrorder'],'status'=>$st); - try { - $json="{ - \"status\":\"pending\", - \"ids\":[{$order->headerdata['ocorder']}] - }" ; - Helper::make_request("POST", "/api/v1/orders/set_status", $json); - } catch(\Exception $ee) { - $this->setErrorTopPage($ee->getMessage()); - return; - } - $order->headerdata['puorderback'] = 1; - $order->save(); + $order->headerdata['hrorderback'] = 1; + $order->save(); + } + + $ret = \App\Modules\HR\Helper::make_request("POST", "/api/orders/update/", json_encode($body, JSON_UNESCAPED_UNICODE)); + $conn->CommitTrans(); + + } catch(\Exception $ee) { + $conn->RollbackTrans(); + + $this->setErrorTopPage($ee->getMessage()); + return; } + $this->setSuccess("Оновлено ".count($elist)." замовлень"); - $this->_eorders = Document::find("meta_name='Order' and content like '%0%' and state <> " . Document::STATE_NEW); + $this->_eorders = Document::find("meta_name='Order' and content like '%0%' and state <> " . Document::STATE_NEW); $this->updateform->orderslist->Reload(); } + + public function onCheck($sender) { + + $token= \App\Modules\HR\Helper::connect(); + if(strlen($token)==0) { + return; + } + try { + $stlist=[]; + + $body=[]; + $body['token'] =$token; + + + $ret = \App\Modules\HR\Helper::make_request("POST", "/api/orders/get_available_statuses", json_encode($body, JSON_UNESCAPED_UNICODE)); + + + foreach($ret['statuses'] as $st){ + $title = $st['title']['ua'] ?? ''; + if($title=='') { + $title = $st['title']['ru'] ?? ''; + } + + if(strlen($title) >0){ + $stlist[$st['id']]=$title; + } + + } + + + $this->filter->status->setOptionList($stlist); + $this->updateform->estatus->setOptionList($stlist); + + } catch(\Exception $ee) { + $this->setErrorTopPage($ee->getMessage()); + return; + } + } } diff --git a/www/app/modules/pu/orders.php b/www/app/modules/pu/orders.php index e8806cea3..79e3b7bbd 100644 --- a/www/app/modules/pu/orders.php +++ b/www/app/modules/pu/orders.php @@ -170,7 +170,7 @@ public function onImport($sender) { foreach ($this->_neworders as $shoporder) { $shoporder->document_number = $shoporder->nextNumber(); if (strlen($shoporder->document_number) == 0) { - $shoporder->document_number = 'PU00001'; + $shoporder->document_number = 'PU-00001'; } if ( $modules['puinsertcust'] == 1) { diff --git a/www/app/util.php b/www/app/util.php index fccba1c89..78bd3377a 100644 --- a/www/app/util.php +++ b/www/app/util.php @@ -162,6 +162,9 @@ public static function handlePhone($tel) { if($phonel==12 && strlen($tel)==10) { $tel = '38'.$tel ; } + if($phonel==10 && strlen($tel)==12) { + $tel = substr($tel,2) ; + } return $tel; } diff --git a/www/templates/modules/hr/orders.html b/www/templates/modules/hr/orders.html index 5079e5471..9910fd823 100644 --- a/www/templates/modules/hr/orders.html +++ b/www/templates/modules/hr/orders.html @@ -5,13 +5,14 @@

Імпорт замовлень

- +
Загрузити статуси + From 60b061bbf2fad778826d5488254ac8e0481cc874 Mon Sep 17 00:00:00 2001 From: "leon.mbs@gmail.com" Date: Sat, 23 Dec 2023 16:40:26 +0200 Subject: [PATCH 10/13] fix --- www/app/entity/doc/order.php | 3 +-- www/app/pages/register/doclist.php | 6 +++--- www/templates/pages/register/doclist.html | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/www/app/entity/doc/order.php b/www/app/entity/doc/order.php index 9c8d7227e..3a9b0cfbf 100644 --- a/www/app/entity/doc/order.php +++ b/www/app/entity/doc/order.php @@ -92,7 +92,6 @@ protected function getNumberTemplate() { public function getRelationBased() { $list = array(); $list['GoodsIssue'] = self::getDesc('GoodsIssue'); - $list['ProdReceipt'] = self::getDesc('ProdReceipt'); if($this->payed==0) { $list['Invoice'] = self::getDesc('Invoice'); } @@ -100,7 +99,7 @@ public function getRelationBased() { $list['Task'] = self::getDesc('Task'); $list['TTN'] = self::getDesc('TTN'); $list['Order'] = self::getDesc('Order'); - $list['OrderCust'] = self::getDesc('OrderCust'); + return $list; } diff --git a/www/app/pages/register/doclist.php b/www/app/pages/register/doclist.php index 64e072855..89021fb90 100644 --- a/www/app/pages/register/doclist.php +++ b/www/app/pages/register/doclist.php @@ -183,9 +183,9 @@ public function doclistOnRow(\Zippy\Html\DataList\DataRow $row) { $doc = $doc->cast(); - $row->add(new Label('name', $doc->meta_desc)); - $row->add(new Label('number', $doc->document_number)); - + $row->add(new ClickLink('name',$this, 'showOnClick'))->setValue($doc->meta_desc); + $row->add(new ClickLink('number',$this, 'showOnClick'))->setValue($doc->document_number); + $row->add(new Label('cust', $doc->customer_name)); $row->add(new Label('branch', $doc->branch_name)); $row->add(new Label('date', H::fd($doc->document_date))); diff --git a/www/templates/pages/register/doclist.html b/www/templates/pages/register/doclist.html index 245163e6d..4de34feac 100644 --- a/www/templates/pages/register/doclist.html +++ b/www/templates/pages/register/doclist.html @@ -129,8 +129,8 @@

Журнал документів - - + + From e389d25a9405a911cc3b683c012195733de5cf3c Mon Sep 17 00:00:00 2001 From: "leon.mbs@gmail.com" Date: Sun, 24 Dec 2023 17:00:24 +0200 Subject: [PATCH 11/13] remove vue ordercust --- www/app/pages/doc/ordercust.php | 443 ++++++++++++++-- www/templates/pages/doc/ordercust.html | 678 ++++++------------------- 2 files changed, 550 insertions(+), 571 deletions(-) diff --git a/www/app/pages/doc/ordercust.php b/www/app/pages/doc/ordercust.php index 5ee787dcc..dd4a08fd2 100644 --- a/www/app/pages/doc/ordercust.php +++ b/www/app/pages/doc/ordercust.php @@ -15,6 +15,7 @@ use Zippy\Html\Form\Date; use Zippy\Html\Form\DropDownChoice; use Zippy\Html\Form\Form; +use Zippy\Html\Form\CheckBox; use Zippy\Html\Form\SubmitButton; use Zippy\Html\Form\TextInput; use Zippy\Html\Label; @@ -36,38 +37,419 @@ public function __construct($docid = 0, $basedocid = 0) { $common = System::getOptions("common"); - - if ($docid > 0) { //загружаем содержимое документа на страницу + $this->add(new Form('docform')); + $this->docform->add(new TextInput('document_number')); + + $this->docform->add(new Date('document_date'))->setDate(time()); + $this->docform->add(new AutocompleteTextInput('customer'))->onText($this, 'OnAutoCustomer'); + $this->docform->add(new SubmitLink('addcust'))->onClick($this, 'addcustOnClick'); + $this->docform->addcust->setVisible( \App\ACL::checkEditRef('CustomerList',false)); + + $this->docform->add(new TextInput('notes')); + + $this->docform->add(new Label('total')); + + $this->docform->add(new SubmitLink('addrow'))->onClick($this, 'addrowOnClick'); + $this->docform->add(new Button('backtolist'))->onClick($this, 'backtolistOnClick'); + $this->docform->add(new SubmitButton('savedoc'))->onClick($this, 'savedocOnClick'); + $this->docform->add(new SubmitButton('execdoc'))->onClick($this, 'savedocOnClick'); + $this->docform->add(new SubmitButton('apprdoc'))->onClick($this, 'savedocOnClick'); + + + //добавление нового контрагента + $this->add(new Form('editcust'))->setVisible(false); + $this->editcust->add(new TextInput('editcustname')); + $this->editcust->add(new TextInput('editphone')); + $this->editcust->add(new Button('cancelcust'))->onClick($this, 'cancelcustOnClick'); + $this->editcust->add(new SubmitButton('savecust'))->onClick($this, 'savecustOnClick'); + + + + $this->add(new Form('editdetail'))->setVisible(false); + $this->editdetail->add(new AutocompleteTextInput('edititem'))->onText($this, 'OnAutoItem'); + $this->editdetail->edititem->onChange($this, 'OnChangeItem', true); + $this->editdetail->add(new TextInput('editquantity'))->setText("1"); + $this->editdetail->add(new TextInput('editprice')); + $this->editdetail->add(new TextInput('editcustcode')); + $this->editdetail->add(new TextInput('editdesc')); + $this->editdetail->add(new Label('qtystock')); + $this->editdetail->add(new Button('canceledit'))->onClick($this, 'cancelrowOnClick'); + $this->editdetail->add(new SubmitButton('saveedit'))->onClick($this, 'saverowOnClick'); + $this->editdetail->add(new ClickLink('openitemsel', $this, 'onOpenItemSel')); + + //добавление нового товара + $this->add(new Form('editnewitem'))->setVisible(false); + $this->editnewitem->add(new TextInput('editnewitemname')); + $this->editnewitem->add(new TextInput('editnewitemcode')); + $this->editnewitem->add(new TextInput('editnewitembarcode')); + $this->editnewitem->add(new CheckBox('editnewitemsnumber')); + + $this->editnewitem->add(new TextInput('editnewmanufacturer')); + $this->editnewitem->add(new TextInput('editnewmsr')); + $this->editnewitem->add(new DropDownChoice('editnewcat', \App\Entity\Category::getList(), 0)); + $this->editnewitem->add(new Button('cancelnewitem'))->onClick($this, 'cancelnewitemOnClick'); + $this->editnewitem->add(new SubmitButton('savenewitem'))->onClick($this, 'savenewitemOnClick'); + + + $this->add(new \App\Widgets\ItemSel('wselitem', $this, 'onSelectItem'))->setVisible(false); + + if ($docid > 0) { //загружаем содержимое документа настраницу $this->_doc = Document::load($docid)->cast(); - $this->_itemlist = $this->_doc->unpackDetails('detaildata'); + $this->docform->document_number->setText($this->_doc->document_number); + + $this->docform->notes->setText($this->_doc->notes); + $this->docform->document_date->setDate($this->_doc->document_date); + $this->docform->customer->setKey($this->_doc->customer_id); + $this->docform->customer->setText($this->_doc->customer_name); + $this->_itemlist = $this->_doc->unpackDetails('detaildata'); } else { $this->_doc = Document::create('OrderCust'); - $this->_doc->document_number = $this->_doc->nextNumber(); - if ($basedocid > 0) { //создание на основании - $basedoc = Document::load($basedocid); - if ($basedoc instanceof Document) { - $this->_basedocid = $basedocid; - if ($basedoc->meta_name == 'Order') { + $this->docform->document_number->setText($this->_doc->nextNumber()); + + + } + $this->calcTotal(); + $this->docform->add(new DataView('detail', new \Zippy\Html\DataList\ArrayDataSource(new \Zippy\Binding\PropertyBinding($this, '_itemlist')), $this, 'detailOnRow'))->Reload(); + if (false == \App\ACL::checkShowDoc($this->_doc)) { + return; + } + } + public function detailOnRow($row) { + $item = $row->getDataItem(); + + $row->add(new Label('item', $item->itemname)); + $row->add(new Label('code', $item->item_code)); + $row->add(new Label('custcode', $item->custcode)); + $row->add(new Label('quantity', H::fqty($item->quantity))); + $row->add(new Label('price', H::fa($item->price))); + $row->add(new Label('msr', $item->msr)); + + $row->add(new Label('amount', H::fa($item->quantity * $item->price))); + $row->add(new ClickLink('edit'))->onClick($this, 'editOnClick'); + + $row->add(new ClickLink('delete'))->onClick($this, 'deleteOnClick'); + } + + public function OnAutoCustomer($sender) { + return Customer::getList($sender->getText(), 2); + } + + + //добавление нового контрагента + public function addcustOnClick($sender) { + $this->editcust->setVisible(true); + $this->docform->setVisible(false); + + $this->editcust->editcustname->setText(''); + + $this->editcust->editphone->setText(''); + } - $order = $basedoc->cast(); + public function savecustOnClick($sender) { + $custname = trim($this->editcust->editcustname->getText()); + if (strlen($custname) == 0) { + $this->setError("Не введено назву"); + return; + } + $cust = new Customer(); + $cust->customer_name = $custname; + $cust->phone = $this->editcust->editphone->getText(); + $cust->phone = \App\Util::handlePhone($cust->phone); - $this->_itemlist = $basedoc->unpackDetails('detaildata'); + if (strlen($cust->phone) > 0 && strlen($cust->phone) != H::PhoneL()) { + $this->setError(""); + $this->setError("Довжина номера телефона повинна бути ".\App\Helper::PhoneL()." цифр"); + return; + } - } - } + $c = Customer::getByPhone($cust->phone); + if ($c != null) { + if ($c->customer_id != $cust->customer_id) { + + $this->setError("Вже існує контрагент з таким телефоном"); + return; } } + $cust->type = Customer::TYPE_SELLER; + $cust->save(); + $this->docform->customer->setText($cust->customer_name); + $this->docform->customer->setKey($cust->customer_id); - $this->add(new \App\Widgets\ItemList('wItemList'))->init(); + $this->editcust->setVisible(false); + $this->docform->setVisible(true); + } + public function cancelcustOnClick($sender) { + $this->editcust->setVisible(false); + $this->docform->setVisible(true); + } + + + public function addrowOnClick($sender) { + $this->editdetail->setVisible(true); + $this->docform->setVisible(false); + $this->_rowid = -1; - if (false == \App\ACL::checkShowDoc($this->_doc)) { + //очищаем форму + $this->editdetail->clean(); + $this->editdetail->edititem->setKey(0); + $this->editdetail->edititem->setText(''); + + $this->editdetail->editquantity->setText("1"); + + $this->editdetail->editprice->setText(""); + $this->editdetail->qtystock->setText(""); + + } + + public function editOnClick($sender) { + $item = $sender->getOwner()->getDataItem(); + $this->editdetail->setVisible(true); + $this->docform->setVisible(false); + + $this->editdetail->editquantity->setText($item->quantity); + $this->editdetail->editprice->setText($item->price); + + + $this->editdetail->editcustcode->setText($item->custcode); + + + + $this->editdetail->edititem->setKey($item->item_id); + $this->editdetail->edititem->setText($item->itemname); + + $this->_rowid = array_search($item, $this->_itemlist, true); + + } + + + public function saverowOnClick($sender) { + $common = System::getOptions("common"); + + + $id = $this->editdetail->edititem->getKey(); + $name = trim($this->editdetail->edititem->getText()); + if ($id == 0) { + $this->setError("Не обрано товар"); return; } + + + $item = Item::load($id); + + $item->quantity = $this->editdetail->editquantity->getText(); + $item->price = $this->editdetail->editprice->getText(); + + + if ($item->price == 0) { + + $this->setWarn("Не вказана ціна"); + } + + + $item->custcode = $this->editdetail->editcustcode->getText(); + + + + if($this->_rowid == -1) { + $this->_itemlist[] = $item; + $this->addrowOnClick(null); + $this->setInfo("Позиція додана") ; + } else { + $this->_itemlist[$this->_rowid] = $item; + $this->cancelrowOnClick(null); + } + + + $this->docform->detail->Reload(); + $this->calcTotal(); + + + } + + public function cancelrowOnClick($sender) { + $this->editdetail->setVisible(false); + $this->docform->setVisible(true); + $this->wselitem->setVisible(false); + + } + + public function deleteOnClick($sender) { + + $item = $sender->owner->getDataItem(); + + $rowid = array_search($item, $this->_itemlist, true); + + $this->_itemlist = array_diff_key($this->_itemlist, array($rowid=> $this->_itemlist[$rowid])); + + + $this->docform->detail->Reload(); + $this->calcTotal(); + + } + + + public function onOpenItemSel($sender) { + $this->wselitem->setVisible(true); + $this->wselitem->Reload(); + } + + + private function checkForm() { + if (strlen($this->_doc->document_number) == 0) { + $this->setError('Введіть номер документа'); + } + if (false == $this->_doc->checkUniqueNumber()) { + $next = $this->_doc->nextNumber(); + $this->docform->document_number->setText($next); + $this->_doc->document_number = $next; + if (strlen($next) == 0) { + $this->setError('Не створено унікальный номер документа'); + } + } + if (count($this->_itemlist) == 0) { + $this->setError("Не введено товар"); + } + + if ($this->docform->customer->getKey() == 0) { + $this->setError("Не обрано постачальника"); + } + + return !$this->isError(); + } + + + + /** + * Расчет итого + * + */ + private function calcTotal() { + + $total = 0; + + foreach ($this->_itemlist as $item) { + $item->amount = $item->price * $item->quantity; + $total = $total + $item->amount; + } + $this->docform->total->setText(H::fa($total)); + } + + public function OnChangeItem($sender) { + $id = $sender->getKey(); + $item = Item::load($id); + + $qty = $item->getQuantity(); + + $this->editdetail->qtystock->setText(H::fqty($qty)); + + $price = $item->getLastPartion(); + $this->editdetail->editprice->setText(H::fa($price)); + + + } + + public function OnAutoItem($sender) { + + $text = trim($sender->getText()); + return Item::findArrayAC($text); + } + + public function onSelectItem($item_id, $itemname, $price=null) { + $this->editdetail->edititem->setKey($item_id); + $this->editdetail->edititem->setText($itemname); + $this->OnChangeItem($this->editdetail->edititem); + } + + public function savedocOnClick($sender) { + if (false == \App\ACL::checkEditDoc($this->_doc)) { + return; + } + + + $this->_doc->document_number = $this->docform->document_number->getText(); + $this->_doc->document_date = $this->docform->document_date->getDate(); + $this->_doc->notes = $this->docform->notes->getText(); + $this->_doc->customer_id = $this->docform->customer->getKey(); + if ($this->_doc->customer_id > 0) { + $customer = Customer::load($this->_doc->customer_id); + $this->_doc->headerdata['customer_name'] = $this->docform->customer->getText(); + } + + + if ($this->checkForm() == false) { + return; + } + + + $common = System::getOptions("common"); + + $this->_doc->packDetails('detaildata', $this->_itemlist); + + $this->_doc->amount = $this->docform->total->getText(); + $isEdited = $this->_doc->document_id > 0; + + $conn = \ZDB\DB::getConnect(); + $conn->BeginTrans(); + try { + if ($this->_basedocid > 0) { + $this->_doc->parent_id = $this->_basedocid; + $this->_basedocid = 0; + } + $this->_doc->save(); + + if ($sender->id == 'execdoc') { + if (!$isEdited) { + $this->_doc->updateStatus(Document::STATE_NEW); + } + $this->_doc->updateStatus(Document::STATE_EXECUTED); + + } else { + + if ($sender->id == 'apprdoc') { + if (!$isEdited) { + $this->_doc->updateStatus(Document::STATE_NEW); + } + + $this->_doc->updateStatus(Document::STATE_WA); + } else { + $this->_doc->updateStatus($isEdited ? Document::STATE_EDITED : Document::STATE_NEW); + } + + + + } + + + + + $conn->CommitTrans(); + } catch(\Throwable $ee) { + global $logger; + $conn->RollbackTrans(); + if ($isEdited == false) { + $this->_doc->document_id = 0; + } + $this->setError($ee->getMessage()); + $logger->error($ee->getMessage() . " Документ " . $this->_doc->meta_desc); + + return; + } + + if (false == \App\ACL::checkShowReg('GRList', false)) { + App::RedirectHome() ; + } else { + App::Redirect("\\App\\Pages\\Register\\GRList"); + } + + } + + + /**************/ public function save($args, $post) { $post = json_decode($post) ; if (false == \App\ACL::checkEditDoc($this->_doc, false, false)) { @@ -154,35 +536,6 @@ public function save($args, $post) { } - public function loaddata($args, $post) { - - $ret['doc'] = []; - $ret['doc']['document_date'] = date('Y-m-d', $this->_doc->document_date) ; - $ret['doc']['document_number'] = $this->_doc->document_number ; - $ret['doc']['notes'] = $this->_doc->notes ; - $ret['doc']['customer_id'] = $this->_doc->customer_id ; - $ret['doc']['customer_name'] = $this->_doc->customer_name ; - $ret['doc']['items'] = []; - foreach($this->_itemlist as $item) { - $ret['doc']['items'][] = array( - 'item_id'=>$item->item_id, - 'itemname'=>$item->itemname , - 'custcode'=>$item->custcode , - 'item_code'=>$item->item_code , - 'desc'=>$item->desc , - 'price'=>H::fa($item->price) , - 'quantity'=>H::fqty($item->quantity) , - 'amount'=>H::fa($item->quantity * $item->price) , - 'msr'=>$item->msr - ); - } - - - return json_encode($ret, JSON_UNESCAPED_UNICODE); - } - - - - + } diff --git a/www/templates/pages/doc/ordercust.html b/www/templates/pages/doc/ordercust.html index e7ee9a761..14aabd7b0 100644 --- a/www/templates/pages/doc/ordercust.html +++ b/www/templates/pages/doc/ordercust.html @@ -4,49 +4,48 @@ - {{={| |}=}} +

Заявка постачальнику

-
-
- -
+ + +
- +
- -
- + -
+ +
+ + +
- +
- +
- +
-
- Додати позицію +
+ Додати позицію @@ -63,25 +62,25 @@

Заявка постачальнику

- + - - - - - - - - - - + + + + + + + + + + + - + @@ -92,539 +91,166 @@

Заявка постачальнику

- - -   -   + +   +   +  
- -
- -
+ +
+
+ +

Введення товару

-
- - +
+
+ +
+ + +
+
+ + Вiдкрити довiдник +
На складі: + +
- - Відкрити довідник -   Додати новий - -
Наявнiсть: {{qtystock}} +
+ +
+ +
+
-
+
+ +
+ +
+
+ +
-
- -
- -
+ +
+ +
+ Наприклад, код з прайсу продавця +
+ +
+ + +
-
- -
- -
-
- -
- - -
- - -
- Наприклад, код з прайсу продавця -
- +
+ + +
+ + +
+
+
+
+
+ +
+
+ +
+

 Новий товар

+
+
+
- - - + +
-
- - + +
- - -
- - - - - + +
- {|={{ }}=|} - -
- - - + } + From d99762a6d8528da53012699c1090153bd535c2ac Mon Sep 17 00:00:00 2001 From: "leon.mbs@gmail.com" Date: Wed, 27 Dec 2023 17:45:29 +0200 Subject: [PATCH 12/13] =?UTF-8?q?=D1=84=D0=B8=D1=81=D0=BA=D0=B0=D0=BB?= =?UTF-8?q?=D0=B8=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD=D1=8B=D0=BA=20=20=D1=87?= =?UTF-8?q?=D0=B5=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- www/app/entity/doc/document.php | 6 +- www/app/modules/ppo/doclist.php | 143 ++++++++++++++++++ www/app/modules/ppo/ppohelper.php | 12 +- www/app/modules/ppo/zlist.php | 8 +- www/app/pages/doc/returnissue.php | 2 + www/app/pages/register/doclist.php | 15 +- www/app/pages/service/armfood.php | 4 +- www/app/pages/service/armpos.php | 4 +- www/templates/modules/ppo/doclist.html | 43 ++++++ www/templates/pages/base.html | 6 + www/templates/pages/register/doclist.html | 42 +++-- .../printforms/report/prrodoclist.tpl | 56 +++++++ 12 files changed, 313 insertions(+), 28 deletions(-) create mode 100644 www/app/modules/ppo/doclist.php create mode 100644 www/templates/modules/ppo/doclist.html create mode 100644 www/templates/printforms/report/prrodoclist.tpl diff --git a/www/app/entity/doc/document.php b/www/app/entity/doc/document.php index 6b766ad36..8192266f8 100644 --- a/www/app/entity/doc/document.php +++ b/www/app/entity/doc/document.php @@ -160,11 +160,7 @@ private function packData() { $value= str_replace('', '', $value) ; - if (strpos($value, '[CDATA[') !== false) { - // \App\System::setWarnMsg('CDATA в поле обьекта'); - // \App\Helper::log(' CDATA в поле обьекта'); - continue; - } + $value = $value ?? ''; if (is_numeric($value) || strlen($value) == 0) { diff --git a/www/app/modules/ppo/doclist.php b/www/app/modules/ppo/doclist.php new file mode 100644 index 000000000..74ab349c8 --- /dev/null +++ b/www/app/modules/ppo/doclist.php @@ -0,0 +1,143 @@ +add(new Form('filter'))->onSubmit($this, 'OnSubmit'); + $this->filter->add(new Date('from', time() - (7 * 24 * 3600))); + $this->filter->add(new Date('to', time())); + + $this->filter->add(new TextInput('doc')); + + + $this->add(new Panel('detail'))->setVisible(false); + + $this->detail->add(new Label('preview')); + + + } + + public function onRow($row) { + $item = $row->getDataItem(); + $row->add(new Label("datadoc", H::fd($item->createdon))); + $row->add(new Label("fndoc", $item->fndoc)); + $row->add(new Label("numdoc", $item->fndoc)); + $row->add(new Label("typedoc", $item->fndoc)); + $row->add(new Label("amount", H::fa($item->amount))); + + + // $this->_tcnt += $item->cnt; + // $this->_tamount += H::fa($item->amount) ; + // $this->_trcnt += $item->rcnt; + // $this->_tramount += H::fa($item->ramount); + + } + + public function OnSubmit($sender) { + $html = $this->generateReport(); + $this->detail->preview->setText($html, true); + \App\Session::getSession()->printform = "" . $html . ""; + + + $this->detail->setVisible(true); + + } + + + public function generateReport() { + $conn = \ZDB\DB::getConnect(); + + + $from = $this->filter->from->getDate(); + $to = $this->filter->to->getDate(); + + $header = array('datefrom' => \App\Helper::fd($from), + 'dateto' => \App\Helper::fd($to) + ); + $header['cnt'] =0; + $header['tam'] =0; + $header['rcnt'] =0; + $header['rtam'] =0; + + $where = "meta_name in ('POSCheck' ,'ReturnIssue','OrderFood') and document_date >= " . $conn->DBDate($from) . " AND document_date <= " . $conn->DBDate($to) ; + $where .= " and content like '%%' "; + + $fndoc = $this->filter->doc->getText(); + + if(strlen($fndoc)>0) { + $ndoc = Document::qstr($fndoc) ;; + $fn = Document::qstr( '%'. $fndoc . '%') ; + + $where .= " and (document_number={$ndoc} or content like {$fn} ) "; + } + + + $detail = array(); + + foreach(Document::findYield($where, "document_id") as $doc) { + $row=[]; + $row['fn'] = $doc->headerdata['fiscalnumber']?? ''; + if($row['fn']=='') continue; + if(($doc->header['fiscaltest']?? false) ) continue; //тестовый + + $row['amount'] = doubleval($doc->headerdata['fiscalamount']?? 0); + if($row['amount']==0) { + $row['amount'] = $doc->amount; + } + $row['amount'] = H::fa($row['amount'] ); + + $row['docdata'] = H::fd($doc->document_date); + $row['docnumber'] = $doc->document_number; + $row['type'] = 'Касовий чек'; + if($doc->meta_name == 'POSCheck' || $doc->meta_name == 'OrderFood') { + $header['cnt']++; + $header['tam'] += $row['amount']; + } + if($doc->meta_name == 'ReturnIssue' && ($doc->headerdata['docnumberback'] ?? '') != '') { + $row['type'] = 'Повернення для '. $doc->headerdata['docnumberback']; + $header['rcnt']++; + $header['rtam'] += $row['amount']; + } + + + $detail[]=$row; + } + + + $header['detail'] = $detail; + + $report = new \App\Report('report/prrodoclist.tpl'); + + $html = $report->generate($header); + + return $html; + } + + + + +} diff --git a/www/app/modules/ppo/ppohelper.php b/www/app/modules/ppo/ppohelper.php index 58c9cc5ec..b3a8ed583 100644 --- a/www/app/modules/ppo/ppohelper.php +++ b/www/app/modules/ppo/ppohelper.php @@ -624,19 +624,14 @@ public static function check($doc ) { $amount3 = $pay['paysum']; $header['amount'] += $doc->headerdata['prepaid']; } - - $header['pay'] = count($header['pays']) > 0; - - $sumpay=0; foreach($header['pays'] as $p ) { $sumpay += $p['paysum'] ; } - $header['disc'] = false; @@ -667,7 +662,9 @@ public static function check($doc ) { } $doc->headerdata["fiscdts"] = "&date=".date('Ymd')."&time={$header['time']}&sum={$header['amount']}"; - + $ret['fiscalamount']= $header['amount']; + + $ret['fiscaltest']= $pos->testing==1 ; return $ret; } @@ -821,6 +818,9 @@ public static function checkback($doc) { self::insertStat($pos->pos_id, 3, $amount0, $amount1, $amount2, $amount3, $doc->document_number); } + $ret['fiscalamount']= $header['amount']; + + $ret['fiscaltest']= $pos->testing==1 ; return $ret; } diff --git a/www/app/modules/ppo/zlist.php b/www/app/modules/ppo/zlist.php index e0c6d9f88..ca663e04e 100644 --- a/www/app/modules/ppo/zlist.php +++ b/www/app/modules/ppo/zlist.php @@ -38,10 +38,10 @@ public function __construct() { $this->filter->add(new TextInput('pos')); $this->filter->add(new TextInput('doc')); - $this->filter->add(new Label('tcnt', new Prop($this, '_tcnt'))); - $this->filter->add(new Label('trcnt', new Prop($this, '_trcnt'))); - $this->filter->add(new Label('tamount', new Prop($this, '_tamount'))); - $this->filter->add(new Label('tramount', new Prop($this, '_tramount'))); + $this->add(new Label('tcnt', new Prop($this, '_tcnt'))); + $this->add(new Label('trcnt', new Prop($this, '_trcnt'))); + $this->add(new Label('tamount', new Prop($this, '_tamount'))); + $this->add(new Label('tramount', new Prop($this, '_tramount'))); $this->add(new DataView('list', new ArrayDataSource(new Prop($this, '_list')), $this, 'OnRow')); $this->add(new ClickLink('csv', $this, 'oncsv')); diff --git a/www/app/pages/doc/returnissue.php b/www/app/pages/doc/returnissue.php index b4f094074..d6332c528 100644 --- a/www/app/pages/doc/returnissue.php +++ b/www/app/pages/doc/returnissue.php @@ -379,6 +379,8 @@ public function savedocOnClick($sender) { $pos->fiscdocnumber = $ret['doclocnumber'] + 1; $pos->save(); $this->_doc->headerdata["fiscalnumber"] = $ret['docnumber']; + $this->_doc->headerdata["fiscalamount"] = $ret['docnumber']; + $this->_doc->headerdata["fiscaltest"] = $ret['fiscaltest']; } else { $this->setError("Не повернено фіскальний номер"); return; diff --git a/www/app/pages/register/doclist.php b/www/app/pages/register/doclist.php index 89021fb90..65ceb1a2d 100644 --- a/www/app/pages/register/doclist.php +++ b/www/app/pages/register/doclist.php @@ -59,6 +59,8 @@ public function __construct($docid = 0) { $filter->customer = 0; $filter->author = 0; $filter->status = 0; + $filter->store = 0; + $filter->mfund = 0; $filter->customer_name = ''; $filter->searchnumber = ''; @@ -70,6 +72,8 @@ public function __construct($docid = 0) { $this->filter->add(new DropDownChoice('doctype', H::getDocTypes(), $filter->doctype)); $this->filter->add(new DropDownChoice('author', \App\Entity\User::findArray('username', 'disabled<>1', 'username'), $filter->author)); $this->filter->add(new DropDownChoice('status', Document::getStateList(), $filter->status)); + $this->filter->add(new DropDownChoice('store', \App\Entity\Store::getList() , $filter->store)); + $this->filter->add(new DropDownChoice('mfund', \App\Entity\MoneyFund::getList(), $filter->mfund)); $this->filter->add(new ClickLink('erase', $this, "onErase")); $this->filter->add(new AutocompleteTextInput('searchcust'))->onText($this, 'OnAutoCustomer'); @@ -138,6 +142,8 @@ public function onErase($sender) { $filter->doctype = 0; $filter->status = 0; $filter->author = 0; + $filter->store = 0; + $filter->mfund = 0; $filter->customer = 0; $filter->customer_name = ''; @@ -165,6 +171,8 @@ public function filterOnSubmit($sender) { $filter->doctype = $this->filter->doctype->getValue(); $filter->author = $this->filter->author->getValue(); $filter->status = $this->filter->status->getValue(); + $filter->store = $this->filter->store->getValue(); + $filter->mfund = $this->filter->mfund->getValue(); $filter->customer = $this->filter->searchcust->getKey(); $filter->customer_name = $this->filter->searchcust->getText(); @@ -731,8 +739,11 @@ private function getWhere($usedate=true) { if ($filter->author > 0) { $where .= " and user_id ={$filter->author} "; } - if ($filter->status > 0) { - $where .= " and state ={$filter->status} "; + if ($filter->mfund > 0) { + $where .= " and document_id in(select document_id from paylist where mf_id = {$filter->mfund} ) "; + } + if ($filter->store > 0) { + $where .= " and document_id in(select document_id from entrylist where stock_id in ( select stock_id from store_stock where store_id= {$filter->store} ) ) "; } $st = $filter->searchtext; if (strlen($st) > 2) { diff --git a/www/app/pages/service/armfood.php b/www/app/pages/service/armfood.php index a5903f7cc..a666e5d37 100644 --- a/www/app/pages/service/armfood.php +++ b/www/app/pages/service/armfood.php @@ -1573,7 +1573,7 @@ public function OnOpenShift($sender) { if ($ret['doclocnumber'] > 0) { $this->_pos->fiscdocnumber = $ret['doclocnumber'] + 1; $this->_pos->save(); - // $this->_doc->headerdata["fiscalnumber"] = $ret['docnumber']; + } \App\Modules\PPO\PPOHelper::clearStat($this->_pos->pos_id); @@ -1757,6 +1757,8 @@ public function onFisc($sender) { $this->_pos->fiscdocnumber = $ret['doclocnumber'] + 1; $this->_pos->save(); $doc->headerdata["fiscalnumber"] = $ret['docnumber']; + $doc->headerdata["fiscalamount"] = $ret['fiscalamount']; + $doc->headerdata["fiscaltest"] = $ret['fiscaltest']; $doc->headerdata["passfisc"] = 0; $doc->save(); $this->setSuccess("Виконано"); diff --git a/www/app/pages/service/armpos.php b/www/app/pages/service/armpos.php index 2fce4ee0b..de50119d0 100644 --- a/www/app/pages/service/armpos.php +++ b/www/app/pages/service/armpos.php @@ -1290,6 +1290,8 @@ public function savedocOnClick($sender) { $this->pos->fiscdocnumber = $ret['doclocnumber'] + 1; $this->pos->save(); $this->_doc->headerdata["fiscalnumber"] = $ret['docnumber']; + $this->_doc->headerdata["fiscalamount"] = $ret['fiscalamount']; + $this->_doc->headerdata["fiscaltest"] = $ret['fiscaltest']; } else { $this->setError("Не повернено фіскальний номер"); $conn->RollbackTrans(); @@ -1419,7 +1421,7 @@ public function OnOpenShift($sender) { if ($ret['doclocnumber'] > 0) { $this->pos->fiscdocnumber = $ret['doclocnumber'] + 1; $this->pos->save(); - // $this->_doc->headerdata["fiscalnumber"] = $ret['docnumber']; + } \App\Modules\PPO\PPOHelper::clearStat($this->pos->pos_id); diff --git a/www/templates/modules/ppo/doclist.html b/www/templates/modules/ppo/doclist.html new file mode 100644 index 000000000..8f8c436c9 --- /dev/null +++ b/www/templates/modules/ppo/doclist.html @@ -0,0 +1,43 @@ + + + Фiскалiзованi чеки + + + +
+
+

Фiскалiзованi чеки

+ +
+ +
+
+ + + +
+
+
+ +
+ +
+ + + \ No newline at end of file diff --git a/www/templates/pages/base.html b/www/templates/pages/base.html index 871718da2..d56b3f821 100644 --- a/www/templates/pages/base.html +++ b/www/templates/pages/base.html @@ -774,6 +774,12 @@

  Журнал z-звiтiв

+
+
- -
- -
+ +
+ +
+ +
+
+ +
+ +
+
+
+ +
+
+ +
+ +
+
+
+
diff --git a/www/templates/printforms/report/prrodoclist.tpl b/www/templates/printforms/report/prrodoclist.tpl new file mode 100644 index 000000000..a0a0b41f6 --- /dev/null +++ b/www/templates/printforms/report/prrodoclist.tpl @@ -0,0 +1,56 @@ +
{{item.itemname}}{{item.item_code}}{{item.custcode}}{{item.msr}}{{item.desc}}{{item.quantity}}{{item.price}}{{item.amount}}     - -     +
Всього:{{this.total}}
+ + + + + + + + + + + + + + + + + + + + + {{#detail}} + + + + + + + + + + + + + + + {{/detail}} + + + + + + + + + + +
+

Фiскалiзованi чеки

+
+ Період з {{datefrom}} по {{dateto}}
+
ДатаНомерФНТипСума
{{docdata}}{{docnumber}}{{fn}}{{type}}{{amount}}
+ Чекiв {{cnt}} на суму {{tam}}. Повернень {{rcnt}} на суму {{rtam}}. +
+ + From 142e93ce35b7a4249dad0eaaefb0c41b5b936555 Mon Sep 17 00:00:00 2001 From: "leon.mbs@gmail.com" Date: Thu, 28 Dec 2023 19:54:31 +0200 Subject: [PATCH 13/13] beta 6.8.11 --- www/composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/composer.json b/www/composer.json index 1a7ef077c..781cf1f99 100644 --- a/www/composer.json +++ b/www/composer.json @@ -1,5 +1,5 @@ { - "description": "Складская система", + "description": "Складська система", "keywords": [ "php", "wms", "erp" ], "homepage": "https://zippy.com.ua/",