Пример #1
0
 public function load()
 {
     $this->initErrorMessages();
     $this->initSuccessMessages();
     $this->addParam('req', isset($_SESSION['action_request']) ? $_SESSION['action_request'] : []);
     unset($_SESSION['action_request']);
     $this->addParam('payment_methods', PaymentMethodManager::getInstance()->selectAdvance('*', ['active', '=', 1], ['name']));
     $this->addParam('partners', PartnerManager::getInstance()->selectAdvance('*', [], ['name']));
     $this->addParam('defaultPaymentMethodId', SettingManager::getInstance()->getSetting('default_payment_method_id'));
 }
Пример #2
0
 private function getFormData()
 {
     $date = date('Y-m-d');
     if (!empty(NGS()->args()->date)) {
         $date = NGS()->args()->date;
     }
     $selectCurrencyId = SettingManager::getInstance()->getSetting('default_currency_id');
     if (isset(NGS()->args()->cur)) {
         $selectCurrencyId = intval(NGS()->args()->cur);
     }
     return array($date, $selectCurrencyId);
 }
Пример #3
0
 public function load()
 {
     $this->initErrorMessages();
     $this->initSuccessMessages();
     $this->addParam('req', isset($_SESSION['action_request']) ? $_SESSION['action_request'] : []);
     $this->addParam('products', ProductManager::getInstance()->selectAdvance('*', [], ['name']));
     unset($_SESSION['action_request']);
     $this->addParam('uoms', UomManager::getInstance()->selectAdvance('*', [], ['name']));
     $this->addParam('manufacturers', ManufacturerManager::getInstance()->selectAdvance('*', [], ['name']));
     $this->addParam('defaultCurrencyId', SettingManager::getInstance()->getSetting('default_currency_id'));
     $this->addParam('defaultUomId', SettingManager::getInstance()->getSetting('default_uom_id'));
 }
Пример #4
0
 public function load()
 {
     $this->initErrorMessages();
     $this->initSuccessMessages();
     $id = intval(NGS()->args()->id);
     $purchaseOrder = PurchaseOrderManager::getInstance()->selectByPK($id);
     if ($purchaseOrder) {
         if (!isset($_SESSION['action_request'])) {
             $_SESSION['action_request'] = ['order_date' => $this->cutSecondsFromDateTime($purchaseOrder->getOrderDate()), 'payment_deadline' => $purchaseOrder->getPaymentDeadline(), 'partnerId' => $purchaseOrder->getPartnerId(), 'note' => $purchaseOrder->getNote()];
         }
         $this->addParam("purchaseOrder", $purchaseOrder);
         $this->addParam('req', $_SESSION['action_request']);
         unset($_SESSION['action_request']);
         $this->addParam('payment_methods', PaymentMethodManager::getInstance()->selectAdvance('*', ['active', '=', 1], ['name']));
         $this->addParam('partners', PartnerManager::getInstance()->selectAdvance('*', [], ['name']));
         $this->addParam('defaultPaymentMethodId', SettingManager::getInstance()->getSetting('default_payment_method_id'));
     }
 }
Пример #5
0
 public function load()
 {
     $this->initErrorMessages();
     $this->initSuccessMessages();
     $id = intval(NGS()->args()->id);
     $product = ProductManager::getInstance()->selectByPK($id);
     if ($product) {
         $this->addParam('product', $product);
         if (!isset($_SESSION['action_request'])) {
             $_SESSION['action_request'] = ['name' => $product->getName(), 'model' => $product->getModel(), 'manufacturerId' => $product->getManufacturerId(), 'uomId' => $product->getUomId()];
         }
         $this->addParam('req', $_SESSION['action_request']);
         unset($_SESSION['action_request']);
         $this->addParam('uoms', UomManager::getInstance()->selectAdvance('*', [], ['name']));
         $this->addParam('manufacturers', ManufacturerManager::getInstance()->selectAdvance('*', [], ['name']));
         $this->addParam('defaultCurrencyId', SettingManager::getInstance()->getSetting('default_currency_id'));
         $this->addParam('defaultUomId', SettingManager::getInstance()->getSetting('default_uom_id'));
     }
 }
Пример #6
0
 public function load()
 {
     $this->initErrorMessages();
     $this->initSuccessMessages();
     $id = intval(NGS()->args()->id);
     $paymentOrder = PaymentTransactionManager::getInstance()->selectByPK($id);
     if ($paymentOrder) {
         if (!isset($_SESSION['action_request'])) {
             $_SESSION['action_request'] = ['date' => $this->cutSecondsFromDateTime($paymentOrder->getDate()), 'partnerId' => $paymentOrder->getPartnerId(), 'billingMethodId' => $paymentOrder->getPaymentMethodId(), 'currencyId' => $paymentOrder->getCurrencyId(), 'note' => $paymentOrder->getNote(), 'signature' => $paymentOrder->getSignature(), 'amount' => $paymentOrder->getAmount(), 'isExpense' => $paymentOrder->getIsExpense(), 'paid' => $paymentOrder->getPaid()];
         }
         $this->addParam("paymentOrder", $paymentOrder);
         $this->addParam('req', $_SESSION['action_request']);
         unset($_SESSION['action_request']);
         $this->addParam('payment_methods', PaymentMethodManager::getInstance()->selectAdvance('*', ['active', '=', 1], ['name']));
         $this->addParam('currencies', CurrencyManager::getInstance()->selectAdvance('*', ['active', '=', 1], ['name']));
         $this->addParam('partners', PartnerManager::getInstance()->selectAdvance('*', [], ['name']));
         $this->addParam('defaultCurrencyId', SettingManager::getInstance()->getSetting('default_currency_id'));
         $this->addParam('defaultPaymentMethodId', SettingManager::getInstance()->getSetting('default_payment_method_id'));
     }
 }
Пример #7
0
 public function getCurrencyRateByDate($date, $currencyId)
 {
     $currencyIso = CurrencyManager::getInstance()->selectByPK($currencyId)->getIso();
     if (strtolower($currencyIso) == strtolower(SettingManager::getInstance()->getSetting('main_currency_iso'))) {
         return 1;
     }
     $oDate = new DateTime($date);
     $sDate = $oDate->format("Y-m-d");
     $sqlStartDate = "DATE_SUB('{$sDate}',INTERVAL 15 DAY)";
     $sqlEndDate = "DATE_ADD('{$sDate}',INTERVAL 1 DAY)";
     $sqlCurrencyIso = "'" . strtoupper($currencyIso) . "'";
     $rows = $this->selectAdvance('*', ['date', '>=', $sqlStartDate, 'AND', 'date', '<=', $sqlEndDate, 'AND', 'iso', '=', $sqlCurrencyIso], 'date', 'DESC');
     if (!empty($rows)) {
         $dto = $rows[0];
         return floatval($dto->getRate()) / floatval($dto->getAmount());
     }
     $rows = $this->selectAdvance('*', ['iso', '=', $sqlCurrencyIso], 'date', 'DESC');
     if (!empty($rows)) {
         $dto = $rows[0];
         return floatval($dto->getRate()) / floatval($dto->getAmount());
     }
     return null;
 }
Пример #8
0
 private function subtracPurchaseOrderLinesByProductSaleOrders($productPurchaseOrderLines, $productSaleOrderLines)
 {
     if (empty($productSaleOrderLines)) {
         return $productPurchaseOrderLines;
     }
     $profit_calculation_method = SettingManager::getInstance()->getSetting('profit_calculation_method');
     foreach ($productSaleOrderLines as $productSaleOrderLine) {
         $productSaleOrderLineQty = $productSaleOrderLine->getQuantity();
         while ($productSaleOrderLineQty > 0) {
             if ($profit_calculation_method == 'max') {
                 $lineId = $this->findMaxProductPriceLineId($productPurchaseOrderLines, $productSaleOrderLine->getOrderDate());
             } else {
                 $lineId = $this->findFirstNonZeroQuantityLineId($productPurchaseOrderLines);
             }
             if ($lineId == 0) {
                 throw new InsufficientProductException($this->calculationProductId);
             }
             $pol = $productPurchaseOrderLines[$lineId];
             $quantity = floatval($pol->getQuantity());
             if ($quantity >= $productSaleOrderLineQty) {
                 $pol->setQuantity($quantity - $productSaleOrderLineQty);
             } else {
                 $pol->setQuantity(0);
             }
             $productSaleOrderLineQty -= $quantity;
         }
     }
     $ret = [];
     foreach ($productPurchaseOrderLines as $productPurchaseOrderLine) {
         if ($productPurchaseOrderLine->getQuantity() > 0) {
             $ret[] = $productPurchaseOrderLine;
         }
     }
     return $this->mapDtosById($ret);
 }
Пример #9
0
 public function getSetting($varName)
 {
     return SettingManager::getInstance()->getSetting($varName);
 }