Example #1
1
 public function Execute()
 {
     $conn = \ZCL\DB\DB::getConnect();
     $store_id = $this->headerdata['store_id'];
     $item = \ZippyERP\ERP\Entity\Item::getSumItem();
     $stock = \ZippyERP\ERP\Entity\Stock::getStock($store_id, $item->item_id, 1, true);
     $discont = 0;
     //скидки  704  счет
     $date = new Carbon();
     $date->setTimestamp($this->document_date);
     $end = $date->endOfMonth()->getTimestamp();
     $begin = $date->startOfMonth()->getTimestamp();
     $sql = " select coalesce(abs(sum(amount)),0) from erp_account_subconto where amount < 0  and account_id=285 and  extcode  = {$store_id} and  document_date  <= " . $conn->DBDate($end);
     $tm = $conn->GetOne($sql);
     //торговая  наценка на  конец периода
     //остатки на  конец периода
     $sql = " select coalesce(sum(quantity),0) AS quantity,coalesce(price,0) as price  from erp_account_subconto sc join erp_store_stock  st on sc.stock_id = st.stock_id where    store_id = {$store_id} and date(document_date) <= " . $conn->DBDate($end);
     $row = $conn->GetRow($sql);
     $ost = $row['quantity'] / 1000;
     $ost = $ost * $row['price'];
     if ($ost == 0) {
         return;
     }
     //выручка
     $sql = " select coalesce(abs(sum(amount)),0) from erp_account_subconto where amount < 0  and account_id=702 and  extcode  = {$store_id} and date(document_date) <= " . $conn->DBDate($end) . " and date(document_date) >= " . $conn->DBDate($begin);
     $saled = $conn->GetOne($sql);
     //выручка сданная в кассу
     $k = ($tm - $discont) / ($ost - $discont);
     $sb = (1 - $k) * $saled;
     //себестоимость
     // списываем  наценку
     Entry::AddEntry("285", "282", $saled - $sb, $this->document_id, $this->document_date);
     // себестоимость реализации
     Entry::AddEntry("902", "282", $sb, $this->document_id, $this->document_date);
     $item = \ZippyERP\ERP\Entity\Item::getSumItem();
     $stockto = \ZippyERP\ERP\Entity\Stock::getStock($store_id, $item->item_id, 1, true);
     $sc = new SubConto($this, 282, 0 - $saled);
     $sc->setStock($stockto->stock_id);
     $sc->setQuantity(0 - $saled * 1000);
     //цена  единицы  товара - 1 копейка.
     $sc->save();
     // НДС
     $nds = H::nds(true);
     Entry::AddEntry("702", "641", $saled * $nds, $this->document_id, $this->document_date);
     return true;
 }
Example #2
0
 /**
  * возвращает  специльный  товар  для  суммвового  учета
  * 
  */
 public static function getSumItem()
 {
     $item = Item::getFirst('item_type=' . Item::ITEM_TYPE_RETSUM);
     if ($item instanceof Item) {
         return $item;
     } else {
         throw new \ZippyERP\System\Exception("Не  найдет товар для  суммового  учета");
     }
 }
Example #3
0
 public function Execute()
 {
     $conn = \ZCL\DB\DB::getConnect();
     $conn->StartTrans();
     $ret = 0;
     // торговая  наценка
     $amount = 0;
     foreach ($this->detaildata as $value) {
         //приниммаем на склад
         $stockto = Stock::getStock($this->headerdata['storeto'], $value['item_id'], $value['partion'], true);
         $sc = new SubConto($this, $value['type'], $value['quantity'] / 1000 * $stockto->price);
         $sc->setStock($stockto->stock_id);
         $sc->setQuantity($value['quantity']);
         $sc->save();
         $store = Store::load($this->headerdata['storefrom']);
         if ($store->store_type == Store::STORE_TYPE_RET) {
             //розница
             $stockfrom = Stock::getFirst("store_id={$this->headerdata['storefrom']} and item_id={$value['item_id']} and price={$value['price']} and partion={$value['partion']} and closed <> 1");
             if ($stockfrom == null) {
                 return false;
             }
             $sc = new SubConto($this, 282, 0 - $value['quantity'] / 1000 * $stockfrom->price);
             $sc->setStock($stockfrom->stock_id);
             $sc->setQuantity(0 - $value['quantity']);
             $sc->save();
             $ret += $value['quantity'] / 1000 * ($value['price'] - $value['partion']);
             $amount += $value['quantity'] / 1000 * $value['partion'];
         }
         if ($store->store_type == Store::STORE_TYPE_RET_SUM) {
             //розница суммовой учет
             //специальный  товар  для  cуммового  учета
             $item = \ZippyERP\ERP\Entity\Item::getSumItem();
             $stockfrom = Stock::getStock($this->headerdata['storefrom'], $item->item_id, 1, true);
             $sc = new SubConto($this, 282, 0 - $value['quantity'] * $value['price']);
             //цена  единицы  товара = 1 копейка.
             $sc->setStock($stockfrom->stock_id);
             $sc->setQuantity(0 - $value['quantity'] * $value['price']);
             //цена  единицы  товара - 1 копейка.
             $sc->save();
             $ret += $value['quantity'] / 1000 * ($value['price'] - $value['partion']);
             $amount += $value['quantity'] / 1000 * $value['partion'];
         }
     }
     if ($amount > 0) {
         // розница
         Entry::AddEntry(281, 282, $amount, $this->document_id, $this->document_date);
         Entry::AddEntry(285, 282, $ret, $this->document_id, $this->document_date);
         $sc = new SubConto($this, 285, $ret);
         $sc->setExtCode($store->store_id);
         $sc->save();
     }
     $conn->CompleteTrans();
     return true;
 }
Example #4
0
 private function generateReport()
 {
     $store = $this->filter->store->getValue();
     $item = $this->filter->item->getKey();
     $from = $this->filter->from->getDate();
     $to = $this->filter->to->getDate();
     $header = array('datefrom' => date('d.m.Y', $from), 'dateto' => date('d.m.Y', $to), "store" => Store::load($store)->storename, "item" => Item::load($item)->itemname, "measure" => Item::load($item)->measure_name);
     $i = 1;
     $detail = array();
     $conn = \ZCL\DB\DB::getConnect();
     $sql = "\n            SELECT\n              t.*,\n              (SELECT\n                  COALESCE(SUM(u.`quantity`), 0)\n                FROM erp_account_subconto u\n                WHERE u.`document_date` < t.dt\n                AND u.`stock_id` = t.`stock_id`) AS begin_quantity\n            FROM (\n            SELECT\n                st.stock_id,\n                price,\n                DATE(sc.document_date) AS dt,\n                SUM(\n                CASE WHEN quantity > 0 THEN quantity ELSE 0 END) AS obin,\n                SUM(\n                CASE WHEN quantity < 0 THEN 0 - quantity ELSE 0 END) AS obout,\n                GROUP_CONCAT(dc.document_number) AS docs\n              FROM\n               erp_account_subconto  sc join erp_store_stock  st on  sc.stock_id = st.stock_id\n               join erp_document  dc  on sc.document_id = dc.document_id\n\n              WHERE st.item_id = {$item}\n              AND st.store_id = {$store}\n              AND DATE(sc.document_date) >= " . $conn->DBDate($from) . "\n              AND DATE(sc.document_date) <= " . $conn->DBDate($to) . "\n              GROUP BY st.stock_id,\n                       st.price,\n                       DATE(sc.document_date)) t\n            ORDER BY dt\n        ";
     $rs = $conn->Execute($sql);
     foreach ($rs as $row) {
         $detail[] = array("no" => $i++, "date" => date("d.m.Y", strtotime($row['dt'])), "documents" => str_replace(',', '<br>', $row['docs']), "price" => H::fm($row['price']), "in" => $row['begin_quantity'] / 1000, "obin" => $row['obin'] / 1000, "obout" => $row['obout'] / 1000, "out" => ($row['begin_quantity'] + $row['obin'] - $row['obout']) / 1000);
     }
     $report = new \ZippyERP\ERP\Report('itemactivity.tpl');
     $html = $report->generate($header, $detail);
     return $html;
 }
Example #5
0
 /**
  * put your comment there...
  * 
  * @param mixed $id    id компонента
  * @param mixed $caller   ссылка на  класс  вызвавшей  страницы
  * @param mixed $callback  имя функции  к  вызвавшей странице  для возврата
  */
 public function __construct($id, $caller, $callback)
 {
     parent::__construct($id);
     $this->caller = $caller;
     $this->callback = $callback;
     $this->add(new Form('itemdetail'));
     $this->itemdetail->add(new TextInput('editname'));
     $this->itemdetail->add(new TextInput('editpriceopt'));
     $this->itemdetail->add(new TextInput('editpriceret'));
     $this->itemdetail->add(new DropDownChoice('editmeasure', \ZippyERP\ERP\Helper::getMeasureList()));
     $this->itemdetail->add(new DropDownChoice('edittype', \ZippyERP\ERP\Entity\Item::getTypeList()));
     $this->itemdetail->add(new DropDownChoice('editgroup', \ZippyERP\ERP\Helper::getItemGroupList()));
     $this->itemdetail->add(new TextInput('editbarcode'));
     $this->itemdetail->add(new TextInput('editcode'));
     $this->itemdetail->add(new TextInput('edituktzed'));
     $this->itemdetail->add(new TextArea('editdescription'));
     $this->itemdetail->add(new SubmitButton('save'))->setClickHandler($this, 'saveOnClick');
     $this->itemdetail->add(new Button('cancel'))->setClickHandler($this, 'cancelOnClick');
 }
Example #6
0
 public function OnChangeItem($sender)
 {
     $item = Item::load($id);
     $this->editdetail->editprice->setText(H::fm($item->priceopt));
     $nds = H::nds();
     $this->editdetail->editpricends->setText(H::fm($item->priceopt + $item->priceopt * $nds));
     $this->updateAjax(array('editprice', 'editpricends', 'qtystock'));
 }
Example #7
0
 public function OnChangeItem($sender)
 {
     $id = $sender->getKey();
     $item = Item::load($id);
     $this->editdetail->editprice->setText(H::fm($item->priceopt));
     $this->editdetail->editpricends->setText(H::fm($item->priceopt));
     if ($this->docform->isnds->IsChecked()) {
         $nds = H::nds();
         $this->editdetail->editpricends->setText(H::fm($item->priceopt + $item->priceopt * $nds));
     }
     // $this->editdetail->editquantity->setText(Item::getQuantity($id, $this->docform->timeline->getDate())/1000);
     $this->updateAjax(array('editprice', 'editpricends'));
 }
Example #8
0
 public function OnChangeItem($sender)
 {
     $id = $sender->getKey();
     $stock = Stock::load($id);
     $item = Item::load($stock->item_id);
     $this->editdetail->editprice->setText(H::fm($stock->price));
     $this->editdetail->qtystock->setText(Stock::getQuantity($id, $this->docform->document_date->getDate()) / 1000 . ' ' . $stock->measure_name);
     $this->updateAjax(array('editprice', 'qtystock'));
 }
Example #9
0
 public function getItem($id)
 {
     return Item::load($id);
 }
Example #10
0
 /**
  * Импорт из  ГНАУ  формат XML...
  *
  * @param mixed $data
  * @return {mixed|TaxInvoiceIncome}    Документ  или  строку  с ошибкой
  */
 public static function import($data)
 {
     if (strpos($data, "<DECLARHEAD>") == false) {
         return "Неверный формат";
     }
     $data = iconv("WINDOWS-1251", "UTF-8", $data);
     $data = str_replace("windows-1251", "utf-8", $data);
     $xml = @simplexml_load_string($data);
     if ($xml instanceof \SimpleXMLElement) {
     } else {
         return "Неверный формат";
     }
     $type = (string) $xml->DECLARHEAD->C_DOC . (string) $xml->DECLARHEAD->C_DOC_SUB;
     if ($type != "J12010" && $type != "F12010") {
         return "Тип  документа  не  Налоговая накладная";
     }
     $doc = new TaxInvoiceIncome();
     $date = (string) $xml->DECLARBODY->HFILL;
     $date = substr($date, 4, 4) . '-' . substr($date, 2, 2) . '-' . substr($date, 0, 2);
     $doc->document_date = strtotime($date);
     $doc->document_number = (string) $xml->DECLARBODY->HNUM;
     $doc->headerdata['based'] = (string) $xml->DECLARBODY->H01G1S;
     $inn = (string) $xml->DECLARBODY->HKSEL;
     $customer = \ZippyERP\ERP\Entity\Customer::loadByInn($inn);
     if ($customer == null) {
         return "Не найден  контрагент  с  ИНН " . $inn;
     }
     $doc->headerdata['customer'] = $customer->customer_id;
     $ernn = (string) $xml->DECLARBODY->HERPN;
     if ($ernn == true) {
         $doc->headerdata['ernn'] = true;
     }
     $details = array();
     foreach ($xml->xpath('//RXXXXG3S') as $node) {
         $details[(string) $node->attributes()->ROWNUM]['name'] = (string) $node;
     }
     foreach ($xml->xpath('//RXXXXG5') as $node) {
         $details[(string) $node->attributes()->ROWNUM]['qty'] = (string) $node;
     }
     foreach ($xml->xpath('//RXXXXG6') as $node) {
         $details[(string) $node->attributes()->ROWNUM]['price'] = (string) $node;
     }
     foreach ($xml->xpath('//RXXXXG105_2S') as $node) {
         $details[(string) $node->attributes()->ROWNUM]['mcode'] = (string) $node;
     }
     foreach ($xml->xpath('//RXXXXG4') as $node) {
         $details[(string) $node->attributes()->ROWNUM]['code'] = (string) $node;
     }
     foreach ($xml->xpath('//RXXXXG4S') as $node) {
         $details[(string) $node->attributes()->ROWNUM]['mname'] = (string) $node;
     }
     $nds = H::nds();
     $doc->detaildata = array();
     foreach ($details as $row) {
         if ($row['code'] > 0) {
             $item = \ZippyERP\ERP\Entity\Item::loadByUktzed($row['code']);
             if ($item == null) {
                 return "Не найден  ТМЦ с  кодом  УКТ ЗЕД: " . $row['code'];
             }
             $item->price = $row['price'] * 100;
             $item->pricends = $item->price + $item->price * $nds;
             $item->quantity = $row['qty'];
             $doc->detaildata[] = $item;
             continue;
         }
         // Пытаемся  найти  по имени
         $item = \ZippyERP\ERP\Entity\Item::getFirst("itemname='" . trim($row['price']) . "'");
         if ($item != null) {
             $item->price = $row['price'] * 100;
             $item->quantity = $row['qty'];
             $doc->detaildata[] = $item;
             continue;
         }
     }
     if (count($details) > count($doc->detaildata)) {
         return "Не найдены  все  записи  таблицы";
     }
     return $doc;
 }
Example #11
0
 public function OnChangeItem($sender)
 {
     $id = $sender->getKey();
     $stock = Stock::load($id);
     $this->editdetail->qtystock->setText(Stock::getQuantity($id, $this->docform->document_date->getDate(), $this->editdetail->edittype->getValue()) / 1000 . ' ' . $stock->measure_name);
     $item = Item::load($stock->item_id);
     $this->editdetail->editprice->setText(H::fm($item->priceopt));
     $nds = 0;
     if ($this->docform->isnds->isChecked()) {
         $nds = H::nds();
     }
     $this->editdetail->editpricends->setText(H::fm($item->priceopt + $item->priceopt * $nds));
     $this->updateAjax(array('editprice', 'editpricends', 'qtystock'));
 }
Example #12
0
 public function OnChangeItem($sender)
 {
     $id = $sender->getKey();
     $stock = Stock::load($id);
     $item = Item::load($stock->item_id);
     $this->editdetail->editprice->setText(H::fm($stock->price));
     $this->updateAjax(array('editprice'));
 }
Example #13
0
 public function OnChangeItem($sender)
 {
     $stock_id = $sender->getKey();
     $stock = Stock::load($stock_id);
     $store = Store::load($this->docform->storeto->getValue());
     if ($store->store_type == Store::STORE_TYPE_OPT) {
     } else {
         $item = Item::load($stock->item_id);
     }
     if ($store->store_type == Store::STORE_TYPE_RET) {
     }
 }
Example #14
0
 public function OnChangeItem($sender)
 {
     $stock_id = $sender->getKey();
     $stock = Stock::load($stock_id);
     $this->editdetail->qtystock->setText(Stock::getQuantity($stock_id, $this->docform->document_date->getDate(), $this->editdetail->edittype->getValue()) / 1000 . ' ' . $stock->measure_name);
     $store = Store::load($this->docform->storeto->getValue());
     if ($store->store_type == Store::STORE_TYPE_OPT) {
         // $this->editdetail->editprice->setText(H::fm($stock->price));
     } else {
         $item = Item::load($stock->item_id);
         $this->editdetail->editprice->setText(H::fm($item->priceret));
     }
     if ($store->store_type == Store::STORE_TYPE_RET) {
         //если  уже   есть  товар  в  магазине  берем  цену  оттуда
         $stock = Stock::getFirst("store_id={$store->store_id} and item_id={$stock->item_id} and closed <> 1");
         if ($stock instanceof Stock) {
             $this->editdetail->editprice->setText(H::fm($stock->price));
         }
     }
 }
Example #15
0
 public function OnAutoItem($sender)
 {
     $text = $sender->getValue();
     return Item::findArray('itemname', "itemname like '%{$text}%' and item_type =" . Item::ITEM_TYPE_STUFF);
 }
Example #16
0
 public function additembtnOnClick($sender)
 {
     $id = $this->docform->e_itemlist->getKey();
     if (isset($this->_itemarr[$id])) {
         $this->setError('Дублирование строки');
         return;
     }
     if ($id == 0) {
         $this->setError('Не выбран  ТМЦ');
         return;
     }
     $item = Item::load($id);
     $item->op = $this->docform->e_itemop->getValue();
     if ($item->op == 0) {
         $this->setError('Не выбран  счет');
         return;
     }
     $item->store_id = $this->docform->e_storelist->getValue();
     if ($item->store_id == 0) {
         $this->setError('Не выбран склад');
         return;
     }
     $store = Store::load($item->store_id);
     $item->store_name = $store->storename;
     $item->qty = 1000 * $this->docform->e_quantity->getText();
     // $item->partion = 100 * $this->docform->e_price->getText();
     $item->price = 100 * $this->docform->e_price->getText();
     if ($item->price == 0) {
         $this->setError('Введите  цену');
         return;
     }
     if (strpos($item->op, '_c') > 0) {
         $stock = \ZippyERP\ERP\Entity\Stock::getStock($item->store_id, $id, $item->price, false);
         if ($stock == null) {
             $this->setError("Не найдена  партия " . H::fm($item->price));
             return;
         }
     }
     $this->_itemarr[$id] = $item;
     $this->docform->itemtable->Reload();
     $this->docform->e_quantity->setText('1');
     $this->docform->e_price->setText('0');
 }
Example #17
0
 public function saverowOnClick($sender)
 {
     $id = $this->editdetail->edittovar->getKey();
     if ($id == 0) {
         $this->setError("Не выбран товар");
         return;
     }
     $item = Item::load($id);
     $item->quantity = 1000 * $this->editdetail->editquantity->getText();
     $item->price = $this->editdetail->editprice->getText() * 100;
     $item->sn = $this->editdetail->editsn->getText();
     $item->warranty = $this->editdetail->editwarranty->getText();
     unset($this->_tovarlist[$this->_rowid]);
     $this->_tovarlist[$item->item_id] = $item;
     $this->editdetail->setVisible(false);
     $this->docform->setVisible(true);
     $this->docform->detail->Reload();
     //очищаем  форму
     $this->editdetail->edittovar->setKey(0);
     $this->editdetail->edittovar->setText('');
     $this->editdetail->editquantity->setText("1");
     $this->editdetail->editprice->setText("");
     $this->editdetail->editsn->setText("");
     $this->editdetail->editwarranty->setText("");
 }
Example #18
0
 public function OnAutoItem($sender)
 {
     $text = $sender->getText();
     return Item::findArray('itemname', "itemname like'%{$text}%' and item_type <>" . Item::ITEM_TYPE_SERVICE . " and item_type <>" . Item::ITEM_TYPE_RETSUM);
 }