public function service() { if (isset(NGS()->args()->id)) { $purchaseOrderId = NGS()->args()->id; } else { $_SESSION['error_message'] = 'Purchase Order ID is missing'; $this->redirect('purchase/list'); } $purchaseOrderManager = PurchaseOrderManager::getInstance(); $purchaseOrderDto = $purchaseOrderManager->selectByPK($purchaseOrderId); if (!isset($purchaseOrderDto)) { $_SESSION['error_message'] = 'Purchase Order with ID ' . NGS()->args()->id . ' does not exists.'; $this->redirect('purchase/list'); } if ($purchaseOrderDto->getCancelled() == 1) { $_SESSION['error_message'] = 'Purchase Order with ID ' . NGS()->args()->id . ' is already cancelled.'; $this->redirect('purchase/list'); } $note = NGS()->args()->note; $purchaseOrderManager->cancelPurchaseOrder($purchaseOrderId, $note); try { PurchaseOrderManager::getInstance()->updateAllDependingSaleOrderLines($purchaseOrderId); $_SESSION['success_message'] = 'Purchase Order Successfully cancelled!'; } catch (InsufficientProductException $exc) { $purchaseOrderManager->restorePurchaseOrder($purchaseOrderId); $productDto = ProductManager::getInstance()->selectByPK($exc->getProductId()); $_SESSION['error_message'] = $productDto->getName() . ' product insufficient!'; } $this->redirectToReferer(); }
public function service() { if (isset(NGS()->args()->id)) { $productId = NGS()->args()->id; } else { $_SESSION['error_message'] = 'Product ID is missing'; $this->redirect('product/list'); } $productManager = ProductManager::getInstance(); $productDto = $productManager->selectByPK($productId); if (!isset($productDto)) { $_SESSION['error_message'] = 'Product with ID ' . NGS()->args()->id . ' does not exists.'; $this->redirect('product/list'); } $res = $productManager->safeDeleteProduct($productId); if ($res) { $_SESSION['success_message'] = 'Product Successfully deleted!'; } else { $_SESSION['error_message'] = 'Product can not be deleted. There are Sale and/or Purchase Order(s) that contains this product.'; $this->redirect('product/list'); } if (strpos($_SERVER['HTTP_REFERER'], 'product/list') === false) { $this->redirect('product/list'); } else { $this->redirectToReferer(); } }
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')); }
public function load() { $productsQuantity = WarehouseManager::getInstance()->getAllProductsQuantity(); $products = ProductManager::getInstance()->getProductListFull([], 'name', 'ASC'); $productIds = ProductManager::getDtosIdsArray($products); $productsPurchaseOrders = PurchaseOrderLineManager::getInstance()->getProductsPurchaseOrders($productIds); $productsSaleOrders = SaleOrderLineManager::getInstance()->getProductsSaleOrders($productIds); $this->addParam('products', $products); $this->addParam('productsQuantity', $productsQuantity); $this->addParam('productsPurchaseOrder', $productsPurchaseOrders); $this->addParam('productsSaleOrder', $productsSaleOrders); }
public function service() { if (!isset(NGS()->args()->product_id)) { new NgsErrorException('Missing Product ID!'); } $product_id = intval(NGS()->args()->product_id); $productDto = ProductManager::getInstance()->selectByPK($product_id); if (!isset($productDto)) { new NgsErrorException('Product does not exist with given ID: ' . NGS()->args()->product_id); } $productQuantityInStock = ProductManager::getInstance()->calculateProductQuantityInStock($product_id); $this->addParam('quantity', $productQuantityInStock); }
public function load() { $this->initErrorMessages(); $this->initSuccessMessages(); $this->addParam('products', ProductManager::getInstance()->selectAdvance('*', [], ['name'])); $this->addParam('currencies', CurrencyManager::getInstance()->selectAdvance('*', ['active', '=', 1], ['name'])); $paymentId = NGS()->args()->id; $purchaseOrders = PurchaseOrderManager::getInstance()->getPurchaseOrdersFull(['id', '=', $paymentId]); if (!empty($purchaseOrders)) { $purchaseOrder = $purchaseOrders[0]; $this->addParam('purchaseOrder', $purchaseOrder); } }
public function service() { try { list($id, $name, $model, $manufacturerId, $uomId) = $this->getFormData(); } catch (RedirectException $exc) { $_SESSION['error_message'] = $exc->getMessage(); $_SESSION['action_request'] = $_REQUEST; $this->redirect($exc->getRedirectTo()); } ProductManager::getInstance()->updateProduct($id, $name, $model, $manufacturerId, $uomId); unset($_SESSION['action_request']); $_SESSION['success_message'] = 'Product Successfully updated!'; $this->redirect('product/' . $id); }
public function load() { $this->initErrorMessages(); $this->initSuccessMessages(); $productId = NGS()->args()->id; $products = ProductManager::getInstance()->getProductListFull(['id', '=', $productId]); if (!empty($products)) { $productSaleQuantity = SaleOrderLineManager::getInstance()->getProductCountInNonCancelledSaleOrders($productId); $productPurchaseQuantity = PurchaseOrderLineManager::getInstance()->getProductCountInNonCancelledPurchaseOrders($productId); $productQuantity = $productPurchaseQuantity - $productSaleQuantity; $product = $products[0]; $this->addParam('product', $product); $this->addParam('productQuantity', $productQuantity); } }
public function service() { if (!isset(NGS()->args()->sale_order_id)) { $_SESSION['error_message'] = 'Sale Order ID is missing'; $this->redirect('sale/list'); } $saleOrderId = intval(NGS()->args()->sale_order_id); try { SaleOrderLineManager::getInstance()->startTransaction(); if (isset(NGS()->args()->lines)) { $jsonLinesArray = NGS()->args()->lines; $linesIdsToNotDelete = []; if (!empty($jsonLinesArray)) { foreach ($jsonLinesArray as $jsonLine) { $line = json_decode($jsonLine); if (isset($line->line_id)) { $linesIdsToNotDelete[] = $line->line_id; SaleOrderLineManager::getInstance()->updateSaleOrderLine($saleOrderId, $line->line_id, $line->product_id, $line->quantity, $line->unit_price, $line->currency_id); } else { $newLineId = SaleOrderLineManager::getInstance()->createSaleOrderLine($saleOrderId, $line->product_id, $line->quantity, $line->unit_price, $line->currency_id); $linesIdsToNotDelete[] = $newLineId; } } } SaleOrderLineManager::getInstance()->deleteWhereIdNotIdIds($saleOrderId, $linesIdsToNotDelete); } else { SaleOrderLineManager::getInstance()->deleteByField('sale_order_id', $saleOrderId); } SaleOrderManager::getInstance()->updateAllDependingSaleOrderLines($saleOrderId); SaleOrderManager::getInstance()->commitTransaction(); } catch (InsufficientProductException $exc) { SaleOrderManager::getInstance()->rollbackTransaction(); $product = \crm\managers\ProductManager::getInstance()->selectByPK($exc->getProductId()); $productInfo = $product->getId(); if (isset($product)) { $productInfo = $product->getName() . " (" . $product->getId() . ")"; } $_SESSION['error_message'] = "Insufficient Product: " . $productInfo; $this->redirect('sale/' . $saleOrderId); } catch (Exception $exc) { SaleOrderManager::getInstance()->rollbackTransaction(); $_SESSION['error_message'] = $exc->getMessage(); $this->redirect('sale/' . $saleOrderId); } $this->redirect('sale/warranty/' . $saleOrderId); }
public function load() { $products = []; if (!empty($_REQUEST['searchText'])) { $searchText = $_REQUEST['searchText']; $words = explode(' ', $searchText); $whereArray = []; foreach ($words as $key => $word) { $whereArray[] = 'name'; $whereArray[] = 'like'; $whereArray[] = "'%" . $word . "%'"; if ($key < count($words) - 1) { $whereArray[] = 'AND'; } } $products = ProductManager::getInstance()->selectAdvance('*', $whereArray, 'name', 'ASC', 0, 1000); } $this->addParam('products', $products); }
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')); } }
public function service() { if (!isset(NGS()->args()->product_id)) { new NgsErrorException('Missing Product ID!'); } if (!isset(NGS()->args()->quantity)) { new NgsErrorException('Missing Product Quantity!'); } $quantity = floatval(NGS()->args()->quantity); $product_id = intval(NGS()->args()->product_id); $productDto = ProductManager::getInstance()->selectByPK($product_id); if (!isset($productDto)) { new NgsErrorException('Product does not exist with given ID: ' . NGS()->args()->product_id); } $productQuantityInStock = ProductManager::getInstance()->calculateProductQuantityInStock($product_id); if ($quantity > $productQuantityInStock) { new NgsErrorException('Not sufficient product in stock. There is ' . $productQuantityInStock . ' in stock'); } }
public function load() { $this->initErrorMessages(); $this->initSuccessMessages(); $limit = 100; list($offset, $sortByFieldName, $selectedFilterSortByAscDesc) = $this->initFilters($limit); $products = ProductManager::getInstance()->getProductListFull([], $sortByFieldName, $selectedFilterSortByAscDesc, $offset, $limit); $productIds = ProductManager::getDtosIdsArray($products); $productsPurchaseOrder = PurchaseOrderLineManager::getInstance()->getProductsPurchaseOrders($productIds); $productsSaleOrder = SaleOrderLineManager::getInstance()->getProductsSaleOrders($productIds); $this->addParam('productsPurchaseOrder', $productsPurchaseOrder); $this->addParam('productsSaleOrder', $productsSaleOrder); $this->addParam('products', $products); $count = ProductManager::getInstance()->getLastSelectAdvanceRowsCount(); if (count($products) == 0 && $count > 0) { $this->redirectIncludedParamsExeptPaging(); } $pagesCount = ceil($count / $limit); $this->addParam('pagesCount', $pagesCount); }
public function load() { $this->initErrorMessages(); $this->initSuccessMessages(); $this->addParam('payment_methods', PaymentMethodManager::getInstance()->selectAdvance('*', ['active', '=', 1], ['name'])); $this->addParam('partners', PartnerManager::getInstance()->selectAdvance('*', [], ['name'])); $this->addParam('products', ProductManager::getInstance()->selectAdvance('*', [], ['name'])); $limit = 100; list($where, $offset, $sortByFieldName, $selectedFilterSortByAscDesc) = $this->initFilters($limit); $saleOrders = SaleOrderManager::getInstance()->getSaleOrdersFull($where, $sortByFieldName, $selectedFilterSortByAscDesc, $offset, $limit); $this->addParam('saleOrders', $saleOrders); $count = SaleOrderManager::getInstance()->getLastSelectAdvanceRowsCount(); if (count($saleOrders) == 0 && $count > 0) { $this->redirectIncludedParamsExeptPaging(); } $pagesCount = ceil($count / $limit); $this->addParam('pagesCount', $pagesCount); $currencyManager = CurrencyManager::getInstance(); $this->addParam('currencies', $currencyManager->mapDtosById($currencyManager->selectAdvance('*', ['active', '=', 1]))); }
public function load() { $this->initErrorMessages(); $this->initSuccessMessages(); $this->addParam('products', ProductManager::getInstance()->selectAdvance('*', [], ['name'])); $this->addParam('currencies', CurrencyManager::getInstance()->selectAdvance('*', ['active', '=', 1], ['name'])); $paymentId = NGS()->args()->id; $saleOrders = SaleOrderManager::getInstance()->getSaleOrdersFull(['id', '=', $paymentId]); if (!empty($saleOrders)) { $saleOrder = $saleOrders[0]; $this->addParam('saleOrder', $saleOrder); } $polSerialNumbersDtos = []; $saleOrderLineIds = $this->getSaleOrderLineIds($saleOrders); if (!empty($saleOrderLineIds)) { $saleOrderLineIdsSql = '(' . implode(',', $saleOrderLineIds) . ')'; $polSerialNumbersDtos = SaleOrderLineSerialNumberManager::getInstance()->selectAdvance('*', ['line_id', 'IN', $saleOrderLineIdsSql]); $polSerialNumbersDtos = $this->mapDtosByLineId($polSerialNumbersDtos); } $this->addParam("polSerialNumbersDtos", $polSerialNumbersDtos); }
public function updateProductCostForOneUnit($productId) { $productUnitCostInBaseCurrency = ProductManager::getInstance()->calculateProductCost($productId, 1, 0); $productDto = ProductManager::getInstance()->selectByPK($productId); $productDto->setUnitCost($this->calculateProductTotalCost($productUnitCostInBaseCurrency)); ProductManager::getInstance()->updateByPK($productDto); }
public function createPurchaseOrderLine($purchaseOrderId, $productId, $quantity, $unitPrice, $currencyId) { $dto = $this->createDto(); $dto->setPurchaseOrderId($purchaseOrderId); $dto->setProductId($productId); $dto->setQuantity($quantity); $dto->setUnitPrice($unitPrice); $dto->setCurrencyId($currencyId); $orderDate = PurchaseOrderManager::getInstance()->selectByPK($purchaseOrderId)->getOrderDate(); $rate = CurrencyRateManager::getInstance()->getCurrencyRateByDate($orderDate, $currencyId); $dto->setCurrencyRate($rate); ProductManager::getInstance()->updateProductCostForOneUnit($productId); return $this->insertDto($dto); }
public function getSaleOrderLinesFull($where = [], $orderByFieldsArray = null, $orderByAscDesc = "ASC", $offset = null, $limit = null) { $rows = $this->selectAdvance('*', $where, $orderByFieldsArray, $orderByAscDesc, $offset, $limit); $productIds = array(); $currencyIds = array(); foreach ($rows as $row) { $productIds[] = $row->getProductId(); $currencyIds[] = $row->getCurrencyId(); } $productIds = array_unique($productIds); $currencyIds = array_unique($currencyIds); $productDtos = ProductManager::getInstance()->selectByPKs($productIds, true); $currencyDtos = CurrencyManager::getInstance()->selectByPKs($currencyIds, true); foreach ($rows as $row) { $row->setProductDto($productDtos[$row->getProductId()]); $row->setCurrencyDto($currencyDtos[$row->getCurrencyId()]); } return $rows; }