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();
 }
Exemple #2
0
 public function load()
 {
     $this->initErrorMessages();
     $this->initSuccessMessages();
     $partnerId = intval(NGS()->args()->id);
     $partner = PartnerManager::getInstance()->selectbyPK($partnerId);
     if ($partner) {
         $this->addParam('currencies', CurrencyManager::getInstance()->selectAdvance('*', ['active', '=', 1], null, null, null, null, true));
         $this->addParam('partner', $partner);
         $partnerSaleOrders = SaleOrderManager::mapDtosById(SaleOrderManager::getInstance()->getPartnerSaleOrders($partnerId));
         $partnerPurchaseOrders = PurchaseOrderManager::mapDtosById(PurchaseOrderManager::getInstance()->getPartnerPurchaseOrders($partnerId));
         $partnerPaymentTransactions = PaymentTransactionManager::mapDtosById(PaymentTransactionManager::getInstance()->getPartnerPaymentTransactions($partnerId));
         $partnerBillingTransactions = PaymentTransactionManager::mapDtosById(PaymentTransactionManager::getInstance()->getPartnerBillingTransactions($partnerId));
         $sales = $this->mapByIdAndGivenField('sale_', 'order_date', $partnerSaleOrders);
         $purchases = $this->mapByIdAndGivenField('purchase_', 'order_date', $partnerPurchaseOrders);
         $paments = $this->mapByIdAndGivenField('payment_', 'date', $partnerPaymentTransactions);
         $billings = $this->mapByIdAndGivenField('billing_', 'date', $partnerBillingTransactions);
         $allDeals = $this->mergeAllDeals($sales, $purchases, $paments, $billings, $partnerSaleOrders, $partnerPurchaseOrders, $partnerPaymentTransactions, $partnerBillingTransactions);
         $this->addParam('allDeals', $allDeals);
         $this->addParam('partnerSaleOrders', $partnerSaleOrders);
         $this->addParam('partnerPurchaseOrders', $partnerPurchaseOrders);
         $this->addParam('partnerPaymentTransactions', $partnerPaymentTransactions);
         $this->addParam('partnerBillingTransactions', $partnerBillingTransactions);
     }
 }
 public function service()
 {
     set_time_limit(120);
     $updateAllSaleOrderLinesCurrencyRates = SaleOrderManager::getInstance()->updateAllLinesCurrencyRates();
     $updateAllPurchaseOrderLinesCurrencyRates = PurchaseOrderManager::getInstance()->updateAllLinesCurrencyRates();
     $updateAllPaymentOrdersCurrencyRates = PaymentTransactionManager::getInstance()->updateAllOrdersCurrencyRates();
     SaleOrderManager::getInstance()->updateAllOrderLines();
     PurchaseOrderManager::getInstance()->updateAllOrderLines();
     $this->addParam('status', true);
     $this->addParam('total_sale_orders', $updateAllSaleOrderLinesCurrencyRates);
     $this->addParam('total_purchase_orders', $updateAllPurchaseOrderLinesCurrencyRates);
     $this->addParam('total_payment_orders', $updateAllPaymentOrdersCurrencyRates);
 }
Exemple #4
0
 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, $partnerId, $date, $paymentDeadlineDate, $note) = $this->getFormData();
     } catch (RedirectException $exc) {
         $_SESSION['error_message'] = $exc->getMessage();
         $_SESSION['action_request'] = $_REQUEST;
         $this->redirect($exc->getRedirectTo());
     }
     PurchaseOrderManager::getInstance()->updatePurchaseOrder($id, $partnerId, $date, $paymentDeadlineDate, $note);
     unset($_SESSION['action_request']);
     $_SESSION['success_message'] = 'Purchase Order Successfully updated!';
     $this->redirect('purchase/' . $id);
 }
 public function service()
 {
     $startDate = NGS()->args()->startDate;
     $endDate = NGS()->args()->endDate;
     $partnerId = intval(NGS()->args()->partner_id);
     $where = ['cancelled', '=', 0, 'and', 'order_date', '>=', "'{$startDate}'", 'and', 'order_date', '<=', "'{$endDate} 23:59:59'"];
     $partnerDto = null;
     if ($partnerId > 0) {
         $partnerDto = PartnerManager::getInstance()->selectByPK($partnerId);
         $where = array_merge($where, ['and', 'partner_id', '=', $partnerId]);
     }
     $rows = PurchaseOrderManager::getInstance()->getPurchaseOrdersFull($where, 'order_date', "DESC");
     $this->exportCsv($rows, $startDate, $endDate, $partnerDto);
 }
 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();
     $purchaseOrderManager->delete($purchaseOrderId);
     $_SESSION['success_message'] = 'Purchase Order Successfully deleted!';
     if (strpos($_SERVER['HTTP_REFERER'], 'purchase/list') === false) {
         $this->redirect('purchase/list');
     } else {
         $this->redirectToReferer();
     }
 }
Exemple #8
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'));
     }
 }
 public function service()
 {
     if (!isset(NGS()->args()->purchase_order_id)) {
         $_SESSION['error_message'] = 'Purchase Order ID is missing';
         $this->redirect('purchase/list');
     }
     $purchaseOrderId = intval(NGS()->args()->purchase_order_id);
     try {
         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;
                         PurchaseOrderLineManager::getInstance()->updatePurchaseOrderLine($purchaseOrderId, $line->line_id, $line->product_id, $line->quantity, $line->unit_price, $line->currency_id);
                     } else {
                         $newLineId = PurchaseOrderLineManager::getInstance()->createPurchaseOrderLine($purchaseOrderId, $line->product_id, $line->quantity, $line->unit_price, $line->currency_id);
                         $linesIdsToNotDelete[] = $newLineId;
                     }
                 }
             }
             PurchaseOrderLineManager::getInstance()->deleteWhereIdNotIdIds($purchaseOrderId, $linesIdsToNotDelete);
         } else {
             PurchaseOrderLineManager::getInstance()->deleteByField('purchase_order_id', $purchaseOrderId);
         }
     } catch (InsufficientProductException $exc) {
         $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('purchase/' . $purchaseOrderId);
     } catch (Exception $exc) {
         $_SESSION['error_message'] = $exc->getMessage();
         $this->redirect('purchase/' . $purchaseOrderId);
     }
     $_SESSION['success_message'] = 'Purchase Order lines successfully saved.';
     PurchaseOrderManager::getInstance()->updateAllDependingSaleOrderLines($purchaseOrderId);
     $this->redirect('purchase/warranty/' . $purchaseOrderId);
 }
Exemple #10
0
 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);
     $purchaseOrders = PurchaseOrderManager::getInstance()->getPurchaseOrdersFull($where, $sortByFieldName, $selectedFilterSortByAscDesc, $offset, $limit);
     $this->addParam('purchaseOrders', $purchaseOrders);
     $count = PurchaseOrderManager::getInstance()->getLastSelectAdvanceRowsCount();
     if (count($purchaseOrders) == 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])));
 }
Exemple #11
0
 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);
     }
     $polSerialNumbersDtos = [];
     $purchaseOrderLineIds = $this->getPurchaseOrderLineIds($purchaseOrders);
     if (!empty($purchaseOrderLineIds)) {
         $purchaseOrderLineIdsSql = '(' . implode(',', $purchaseOrderLineIds) . ')';
         $polSerialNumbersDtos = PurchaseOrderLineSerialNumberManager::getInstance()->selectAdvance('*', ['line_id', 'IN', $purchaseOrderLineIdsSql]);
         $polSerialNumbersDtos = $this->mapDtosByLineId($polSerialNumbersDtos);
     }
     $this->addParam("polSerialNumbersDtos", $polSerialNumbersDtos);
 }
Exemple #12
0
 public function load()
 {
     list($startDate, $endDate) = $this->getFormData();
     $this->addParam('startDate', $startDate);
     $this->addParam('endDate', $endDate);
     $partnerSaleOrders = AdvancedAbstractManager::mapDtosById(SaleOrderManager::getInstance()->getSaleOrdersFull(['cancelled', '=', 0, 'AND', 'order_date', '>=', "'" . $startDate . "'", 'AND', 'order_date', '<=', "DATE_ADD('{$endDate}' ,INTERVAL 1 DAY)"], ['order_date'], 'DESC'));
     $partnerPurchaseOrders = AdvancedAbstractManager::mapDtosById(PurchaseOrderManager::getInstance()->getPurchaseOrdersFull(['cancelled', '=', 0, 'AND', 'order_date', '>=', "'" . $startDate . "'", 'AND', 'order_date', '<=', "DATE_ADD('{$endDate}' ,INTERVAL 1 DAY)"], ['order_date'], 'DESC'));
     $partnerPaymentTransactions = AdvancedAbstractManager::mapDtosById(PaymentTransactionManager::getInstance()->getPaymentListFull(['cancelled', '=', 0, 'AND', 'amount', '>', 0, 'AND', 'date', '>=', "'" . $startDate . "'", 'AND', 'date', '<=', "DATE_ADD('{$endDate}' ,INTERVAL 1 DAY)"], ['date'], 'DESC'));
     $partnerBillingTransactions = AdvancedAbstractManager::mapDtosById(PaymentTransactionManager::getInstance()->getPaymentListFull(['cancelled', '=', 0, 'AND', 'amount', '<', 0, 'AND', 'date', '>=', "'" . $startDate . "'", 'AND', 'date', '<=', "DATE_ADD('{$endDate}' ,INTERVAL 1 DAY)"], ['date'], 'DESC'));
     $sales = $this->mapByIdAndGivenField('sale_', 'order_date', $partnerSaleOrders);
     $purchases = $this->mapByIdAndGivenField('purchase_', 'order_date', $partnerPurchaseOrders);
     $paments = $this->mapByIdAndGivenField('payment_', 'date', $partnerPaymentTransactions);
     $billings = $this->mapByIdAndGivenField('billing_', 'date', $partnerBillingTransactions);
     $allDeals = $this->mergeAllDeals($sales, $purchases, $paments, $billings, $partnerSaleOrders, $partnerPurchaseOrders, $partnerPaymentTransactions, $partnerBillingTransactions);
     $this->addParam('allDeals', $allDeals);
     $this->addParam('partnerSaleOrders', $partnerSaleOrders);
     $this->addParam('partnerPurchaseOrders', $partnerPurchaseOrders);
     $this->addParam('partnerPaymentTransactions', $partnerPaymentTransactions);
     $this->addParam('partnerBillingTransactions', $partnerBillingTransactions);
     $this->addParam('currencies', CurrencyManager::getInstance()->selectAdvance('*', ['active', '=', 1], null, null, null, null, true));
 }
Exemple #13
0
 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');
     }
     if (isset(NGS()->args()->paid)) {
         $paid = NGS()->args()->paid;
     } else {
         $_SESSION['error_message'] = 'Paid parameter is missing';
         $this->redirect('purchase/' . NGS()->args()->id);
     }
     $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');
     }
     $purchaseOrderManager->setPaid($purchaseOrderId, $paid);
 }
 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() == 0) {
         $_SESSION['error_message'] = 'Purchase Order with ID ' . NGS()->args()->id . ' is not cancelled.';
         $this->redirect('purchase/list');
     }
     $purchaseOrderManager->restorePurchaseOrder($purchaseOrderId);
     $_SESSION['success_message'] = 'Purchase Order Successfully restored!';
     $this->redirectToReferer();
 }
Exemple #15
0
 public function load()
 {
     $this->initErrorMessages();
     $this->initSuccessMessages();
     $partnerId = intval(NGS()->args()->id);
     $partner = PartnerManager::getInstance()->getPartnerFull($partnerId);
     if ($partner) {
         $this->addParam('partner', $partner);
         $partnerSaleOrders = SaleOrderManager::getInstance()->getPartnerSaleOrders($partnerId);
         $partnerPurchaseOrders = PurchaseOrderManager::getInstance()->getPartnerPurchaseOrders($partnerId);
         $partnerPaymentTransactions = PaymentTransactionManager::getInstance()->getPartnerPaymentTransactions($partnerId);
         $partnerBillingTransactions = PaymentTransactionManager::getInstance()->getPartnerBillingTransactions($partnerId);
         $partnerInitialDept = PartnerInitialDeptManager::getInstance()->getPartnerInitialDept($partnerId);
         $this->addParam('partnerSaleOrders', $partnerSaleOrders);
         $this->addParam('partnerPurchaseOrders', $partnerPurchaseOrders);
         $this->addParam('partnerPaymentTransactions', $partnerPaymentTransactions);
         $this->addParam('partnerBillingTransactions', $partnerBillingTransactions);
         $dept = CalculationManager::getInstance()->calculatePartnerDeptBySalePurchaseAndPaymentTransations($partnerSaleOrders, $partnerPurchaseOrders, $partnerPaymentTransactions, $partnerBillingTransactions, $partnerInitialDept);
         $this->addParam('partnerDept', $dept);
         $currencyManager = CurrencyManager::getInstance();
         $this->addParam('currencies', $currencyManager->mapDtosById($currencyManager->selectAdvance('*', ['active', '=', 1], ['name'])));
     }
 }
Exemple #16
0
 public function load()
 {
     $this->initErrorMessages();
     $this->initSuccessMessages();
     $limit = 100;
     list($offset, $sortByFieldName, $selectedFilterSortByAscDesc) = $this->initFilters($limit);
     $partnerManager = PartnerManager::getInstance();
     $partners = $partnerManager->selectAdvance('*', [], $sortByFieldName, $selectedFilterSortByAscDesc, $offset, $limit);
     $partnerIds = $partnerManager->getDtosIdsArray($partners);
     $partnersSaleOrdersMappedByPartnerId = [];
     $partnersPurchaseOrdersMappedByPartnerId = [];
     $partnersTransactionsMappedByPartnerId = [];
     $partnersInitialDept = [];
     if (!empty($partnerIds)) {
         $partnersSaleOrdersMappedByPartnerId = SaleOrderManager::getInstance()->getPartnersSaleOrders($partnerIds);
         $partnersPurchaseOrdersMappedByPartnerId = PurchaseOrderManager::getInstance()->getPartnersPurchaseOrders($partnerIds);
         $partnersPaymentTransactionsMappedByPartnerId = PaymentTransactionManager::getInstance()->getPartnersPaymentTransactions($partnerIds);
         $partnersBillingTransactionsMappedByPartnerId = PaymentTransactionManager::getInstance()->getPartnersBillingTransactions($partnerIds);
         $partnersInitialDept = PartnerInitialDeptManager::getInstance()->getPartnersInitialDept($partnerIds);
     }
     $partnersDept = CalculationManager::getInstance()->calculatePartnersDeptBySalePurchaseAndPaymentTransations($partnersSaleOrdersMappedByPartnerId, $partnersPurchaseOrdersMappedByPartnerId, $partnersPaymentTransactionsMappedByPartnerId, $partnersBillingTransactionsMappedByPartnerId, $partnersInitialDept);
     $this->addParam('partnersSaleOrdersMappedByPartnerId', $partnersSaleOrdersMappedByPartnerId);
     $this->addParam('partnersPurchaseOrdersMappedByPartnerId', $partnersPurchaseOrdersMappedByPartnerId);
     $this->addParam('partnersPaymentTransactionsMappedByPartnerId', $partnersPaymentTransactionsMappedByPartnerId);
     $this->addParam('partnersBillingTransactionsMappedByPartnerId', $partnersBillingTransactionsMappedByPartnerId);
     $this->addParam('partnersDept', $partnersDept);
     $this->addParam('partners', $partners);
     $count = PartnerManager::getInstance()->getLastSelectAdvanceRowsCount();
     if (count($partners) == 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], ['name'])));
 }
Exemple #17
0
 public function calculatePartnerDeptBySalePurchaseAndPaymentTransations($id)
 {
     $partnerSaleOrders = SaleOrderManager::getInstance()->getPartnerSaleOrders($id);
     $partnerPurchaseOrders = PurchaseOrderManager::getInstance()->getPartnerPurchaseOrders($id);
     $partnerPaymentTransactions = PaymentTransactionManager::getInstance()->getPartnerPaymentTransactions($id);
     $partnerBillingTransactions = PaymentTransactionManager::getInstance()->getPartnerBillingTransactions($id);
     $partnerInitialDept = PartnerInitialDeptManager::getInstance()->getPartnerInitialDept($id);
     return CalculationManager::getInstance()->calculatePartnerDeptBySalePurchaseAndPaymentTransations($partnerSaleOrders, $partnerPurchaseOrders, $partnerPaymentTransactions, $partnerBillingTransactions, $partnerInitialDept);
 }
Exemple #18
0
 private function getPurchaseOrdersDatesMappedBySN($pol_searial_numbers)
 {
     $snMappedByPolIds = [];
     foreach ($pol_searial_numbers as $pol_searial_number) {
         $snMappedByPolIds[$pol_searial_number->getLineId()][] = $pol_searial_number->getSerialNumber();
     }
     $polDtos = PurchaseOrderLineManager::getInstance()->selectByPKs(array_keys($snMappedByPolIds));
     $poIdsMappedByPolId = $this->getPoIdsMappedByPolIds($polDtos);
     $poDtos = PurchaseOrderManager::getInstance()->getPurchaseOrdersFull($where = ['id', 'in', '(' . implode(',', array_unique(array_values($poIdsMappedByPolId))), ')']);
     $poDtosMappedByID = SaleOrderManager::mapDtosById($poDtos);
     $ret = [];
     foreach ($poIdsMappedByPolId as $polId => $poId) {
         foreach ($snMappedByPolIds[$polId] as $sn) {
             if (isset($poDtosMappedByID[$poId])) {
                 $ret[$sn] = [$poDtosMappedByID[$poId]->getOrderDate(), $poDtosMappedByID[$poId]->getPartnerDto()->getName()];
             }
         }
     }
     return $ret;
 }
 public function getProductsPurchaseOrders($productIds)
 {
     $poLines = $this->mapper->getNonCancelledProductsPurchaseOrders($productIds);
     $poIdsMappedByProductId = [];
     $allPurchaseOrdersIds = [];
     foreach ($poLines as $po) {
         $poIdsMappedByProductId[$po->getProductId()][] = $po->getPurchaseOrderId();
         $allPurchaseOrdersIds[] = intval($po->getPurchaseOrderId());
     }
     $allPurchaseOrdersIds = array_unique($allPurchaseOrdersIds);
     if (!empty($allPurchaseOrdersIds)) {
         $idsSql = '(' . implode(',', $allPurchaseOrdersIds) . ')';
         $pos = PurchaseOrderManager::getInstance()->selectAdvance('*', ['id', 'IN', $idsSql], null, null, null, null, true);
     }
     foreach ($poIdsMappedByProductId as &$r) {
         $r = array_unique($r);
     }
     $ret = [];
     foreach ($productIds as $productId) {
         if (!array_key_exists($productId, $poIdsMappedByProductId)) {
             $poIdsMappedByProductId[$productId] = [];
         }
         $ret[$productId] = [];
         foreach ($poIdsMappedByProductId[$productId] as $poId) {
             if (array_key_exists($poId, $pos)) {
                 $ret[$productId][] = $pos[$poId];
             }
         }
     }
     return $ret;
 }