public function load() { list($startDate, $endDate) = [NGS()->args()->startDate, NGS()->args()->endDate]; $expenseSaleOrders = SaleOrderManager::getInstance()->getSaleOrdersFull(['cancelled', '=', 0, 'AND', 'is_expense', '=', 1, 'AND', 'order_date', '>=', "'" . $startDate . "'", 'AND', 'order_date', '<=', "DATE_ADD('{$endDate}' ,INTERVAL 1 DAY)"], ['order_date'], 'DESC'); $this->addParam('currencies', CurrencyManager::getInstance()->mapDtosById(CurrencyManager::getInstance()->selectAdvance('*', ['active', '=', 1]))); $this->addParam("expenseSaleOrders", $expenseSaleOrders); }
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 load() { list($date, $curr) = $this->getFormData(); $this->addParam('date', $date); $this->addParam('selectedCurrencyId', $curr); $this->addParam('currencies', CurrencyManager::getInstance()->selectAdvance('*', ['active', '=', 1], ['name'])); $paymentTransactionManager = PaymentTransactionManager::getInstance(); $nonCancelledPaymentOrdersByCurrency = $paymentTransactionManager->getNonCancelledPaymentOrdersByCurrency($date, $curr); $cashboxAmount = -$nonCancelledPaymentOrdersByCurrency; $this->addParam("amount", $cashboxAmount); }
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('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')); }
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 getInitialDeptsFull($where = [], $orderByFieldsArray = null, $orderByAscDesc = "ASC", $offset = null, $limit = null) { $rows = $this->selectAdvance('*', $where, $orderByFieldsArray, $orderByAscDesc, $offset, $limit); $currencyIds = array(); foreach ($rows as $row) { $currencyIds[] = intval($row->getCurrencyId()); } $currencyIds = array_unique($currencyIds); $currencyDtos = CurrencyManager::getInstance()->selectByPKs($currencyIds, true); foreach ($rows as $row) { $row->setCurrencyDto($currencyDtos[$row->getCurrencyId()]); } return $rows; }
public function exportCsv($rows, $startDate, $endDate, $partnerDto = null) { $currencyDtosMappedById = CurrencyManager::getInstance()->selectAdvance('*', [], null, null, null, null, true); header('Content-type: text/csv; charset=UTF-8'); header('Content-Disposition: attachment; filename=observers.csv'); $output = fopen('php://output', 'w'); fputs($output, chr(0xef) . chr(0xbb) . chr(0xbf)); $totalPurchases = [1 => 0, 2 => 0]; foreach ($rows as $row) { $totalAmountMappedByCurrencyId = $row->getTotalAmount(); foreach ($totalAmountMappedByCurrencyId as $curId => $tAmount) { $totalPurchases[$curId] += $tAmount; } } $totalAmountsTextsArray = []; foreach ($totalPurchases as $currencyId => $ta) { $currencyDto = $currencyDtosMappedById[$currencyId]; $templateChar = $currencyDto->getTemplateChar(); $totalAmountsTextsArray[] = $ta . ' ' . $templateChar; } fputcsv($output, ['Star Date', 'End Date', 'Total Amount AMD', 'Total Profit AMD']); fputcsv($output, [$startDate, $endDate, implode(' ', $totalAmountsTextsArray)]); fputcsv($output, ['']); fputcsv($output, ['']); fputcsv($output, ['']); fputcsv($output, ['']); fputcsv($output, ['']); fputcsv($output, ['Date', 'Partner', 'Total Amount AMD', 'Profit AMD']); foreach ($rows as $row) { fputcsv($output, ['']); $rta = $row->getTotalAmount(); $totalAmountsTextsArray = []; foreach ($rta as $currencyId => $ta) { $currencyDto = $currencyDtosMappedById[$currencyId]; $templateChar = $currencyDto->getTemplateChar(); $totalAmountsTextsArray[] = $ta . ' ' . $templateChar; } fputcsv($output, [$row->getOrderDate(), $row->getPartnerDto()->getName(), implode(' ;', $totalAmountsTextsArray)]); $purchaseOrderLinesDtos = $row->getPurchaseOrderLinesDtos(); fputcsv($output, ['', 'Product', 'Qty', 'Amount']); foreach ($purchaseOrderLinesDtos as $purchaseOrderLineDto) { $currencyChar = $purchaseOrderLineDto->getCurrencyDto()->getTemplateChar(); fputcsv($output, ['', $purchaseOrderLineDto->getProductDto()->getName(), $purchaseOrderLineDto->getQuantity(), $purchaseOrderLineDto->getUnitPrice() . ' ' . $currencyChar]); } } exit; }
public function load() { $this->initErrorMessages(); $this->initSuccessMessages(); $limit = 100; list($where, $offset, $sortByFieldName, $selectedFilterSortByAscDesc) = $this->initFilters($limit); $billing = PaymentTransactionManager::getInstance()->getPaymentListFull($where, $sortByFieldName, $selectedFilterSortByAscDesc, $offset, $limit); $this->addParam('billings', $billing); $count = PaymentTransactionManager::getInstance()->getLastSelectAdvanceRowsCount(); if (count($billing) == 0 && $count > 0) { $this->redirectIncludedParamsExeptPaging(); } $pagesCount = ceil($count / $limit); $this->addParam('pagesCount', $pagesCount); $this->addParam('partners', PartnerManager::getInstance()->selectAdvance('*', [], ['name'])); $this->addParam('currencies', CurrencyManager::getInstance()->selectAdvance('*', ['active', '=', 1], ['name'])); }
public function service() { if (!isset(NGS()->args()->partner_id)) { new NgsErrorException('Missing Partner ID!'); } $partner_id = intval(NGS()->args()->partner_id); $partnerDto = PartnerManager::getInstance()->selectByPK($partner_id); if (!isset($partnerDto)) { new NgsErrorException('Partner does not exist with given ID: ' . NGS()->args()->partner_id); } $dept = PartnerManager::getInstance()->calculatePartnerDeptBySalePurchaseAndPaymentTransations($partner_id); $currenciesMappedById = CurrencyManager::getInstance()->selectAdvance('*', ['active', '=', 1], null, null, null, null, true); foreach ($dept as $currencyId => $amount) { $currencyDto = $currenciesMappedById[$currencyId]; $this->addParam($currencyDto->getIso(), [$amount, $currencyDto->getTemplateChar(), $currencyDto->getSymbolPosition()]); } }
public function load() { $this->initErrorMessages(); $this->initSuccessMessages(); $id = intval(NGS()->args()->id); $partners = PartnerManager::getInstance()->getPartnersFull(['id', '=', $id]); if (!empty($partners)) { $this->addParam('currencies', CurrencyManager::getInstance()->selectAdvance('*', ['active', '=', 1], ['name'])); $partner = $partners[0]; if (!isset($_SESSION['action_request'])) { $_SESSION['action_request'] = ['name' => $partner->getName(), 'email' => $partner->getEmail(), 'address' => $partner->getAddress(), 'phone' => $partner->getPhone(), 'initial_dept' => $partner->getPartnerInitialDeptDtos()]; } $this->addParam("partner", $partner); $this->addParam('req', $_SESSION['action_request']); unset($_SESSION['action_request']); } }
public function getPurchaseOrderLinesFull($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; }
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(); $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')); } }
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)); }
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 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']))); } }
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; }
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']))); }
public function getPaymentListFull($where = [], $orderByFieldsArray = null, $orderByAscDesc = "ASC", $offset = null, $limit = null) { $rows = $this->selectAdvance('*', $where, $orderByFieldsArray, $orderByAscDesc, $offset, $limit); $partnerIds = array(); $paymentMethodIds = array(); $currenciesIds = array(); foreach ($rows as $row) { $partnerIds[] = $row->getPartnerId(); $paymentMethodIds[] = $row->getPaymentMethodId(); $currenciesIds[] = $row->getCurrencyId(); } $partnerIds = array_unique($partnerIds); $paymentMethodIds = array_unique($paymentMethodIds); $currenciesIds = array_unique($currenciesIds); $partnerDtos = PartnerManager::getInstance()->selectByPKs($partnerIds, true); $paymentMethodDtos = PaymentMethodManager::getInstance()->selectByPKs($paymentMethodIds, true); $currencyDtos = CurrencyManager::getInstance()->selectByPKs($currenciesIds, true); foreach ($rows as $row) { $row->setPartnerDto($partnerDtos[$row->getPartnerId()]); $row->setPaymentMethodDto($paymentMethodDtos[$row->getPaymentMethodId()]); $row->setCurrencyDto($currencyDtos[$row->getCurrencyId()]); } return $rows; }