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; }
public function Execute() { $cash = MoneyFund::getCash(); $ret = ""; $optype = $this->headerdata['optype']; if ($optype == self::TYPEOP_CUSTOMER) { $ret = Entry::AddEntry(30, 36, $this->headerdata['amount'], $this->document_id, $this->document_date); $sc = new SubConto($this, 36, 0 - $this->headerdata['amount']); $sc->setCustomer($this->headerdata['opdetail']); $sc->save(); } if ($optype == self::TYPEOP_CASH) { $ret = Entry::AddEntry(30, 372, $this->headerdata['amount'], $this->document_id, $this->document_date); $sc = new SubConto($this, 372, 0 - $this->headerdata['amount']); $sc->setEmployee($this->headerdata['opdetail']); $sc->save(); } if ($optype == self::TYPEOP_BANK) { $ret = Entry::AddEntry(30, 31, $this->headerdata['amount'], $this->document_id, $this->document_date); $sc = new SubConto($this, 31, 0 - $this->headerdata['amount']); $sc->setMoneyfund($this->headerdata['opdetail']); $sc->save(); } if ($optype == self::TYPEOP_RET) { $store_id = $this->headerdata['opdetail']; // магазин $ret = Entry::AddEntry(30, 702, $this->headerdata['amount'], $this->document_id, $this->document_date); $sc = new SubConto($this, 702, 0 - $this->headerdata['amount']); $sc->setExtCode($this->headerdata['opdetail']); $sc->save(); $store = \ZippyERP\ERP\Entity\Store::load($store_id); if ($store->store_type == \ZippyERP\ERP\Entity\Store::STORE_TYPE_RET_SUM) { $nds = \ZippyERP\ERP\Helper::nds(true); Entry::AddEntry(702, 643, $nds * $this->headerdata['amount'], $this->document_id, $this->document_date); } } //касса $sc = new SubConto($this, 30, $this->headerdata['amount']); $sc->setMoneyfund($cash->id); $sc->save(); if (strlen($ret) > 0) { throw new \Exception($ret); } return true; }
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')); }
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')); }
/** * Расчет итого * */ private function calcTotal() { $total = 0; foreach ($this->_tovarlist as $tovar) { $total = $total + $tovar->price * ($tovar->quantity / 1000); } $nds = $total * H::nds(true); $this->docform->totalnds->setText(H::fm($nds)); $this->docform->total->setText(H::fm($total)); }
public function onIsnds($sender) { foreach ($this->_itemlist as $item) { if ($sender->isChecked() == false) { $item->price = $item->pricends; } else { $item->price = $item->pricends - $item->pricends * H::nds(true); } } $this->docform->detail->Reload(); }
/** * Импорт из ГНАУ формат 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; }
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')); }