示例#1
0
 /**
  * This action display the view to china agents
  *
  * @author Erick Guevara Martínez
  */
 public function entriesAction()
 {
     // Get criteria to filter requisition entries
     if ($this->getRequest()->isPost()) {
         $post[RequisitionEntry::ID_REQUISITION] = $this->getRequest()->getParam(RequisitionEntry::ID_REQUISITION);
         $post[RequisitionEntry::STATUS] = $this->getRequest()->getParam(RequisitionEntry::STATUS);
         $post["id_supplier"] = $this->getRequest()->getParam("id_supplier", "");
         $post["id_destination_country"] = $this->getRequest()->getParam("id_destination_country", "");
         $post["startDate"] = $this->getRequest()->getParam("startDate", "");
         $post["endDate"] = $this->getRequest()->getParam("endDate", "");
         $post["key_mother"] = $this->getRequest()->getParam("key_mother", "");
         $post["order"] = $this->getRequest()->getParam("order", "");
     }
     $accessRole = $this->getUser()->getAccessRole();
     $accessRoleManager = new AccessRoleManager();
     $suppliers = $accessRoleManager->getAssociateSuppliers($accessRole);
     $products = ProductQuery::create()->whereAdd(Product::ID_SUPPLIER, $suppliers->getPrimaryKeys())->find();
     // Creates an array with the status can be displayed in this view
     $allowedStatus = array("Pending Price" => RequisitionEntry::$Status["Pending Price"], "Pending Price Auth" => RequisitionEntry::$Status["Pending Price Auth"], "PI Requested" => RequisitionEntry::$Status["PI Requested"]);
     // If don't have a status filter then search by allowed status
     $requisitionEntriesQuery = RequisitionEntryQuery::create()->filter($post)->whereAdd(RequisitionEntry::ID_PRODUCT, $products->getPrimaryKeys());
     if ($post[RequisitionEntry::STATUS] == "") {
         $requisitionEntriesQuery->whereAdd("RequisitionEntry." . RequisitionEntry::STATUS, $allowedStatus, BaseQuery::IN);
     }
     // Filter all requisition entries belonging to a requisition with the same
     if ($post["id_destination_country"] != "") {
         $requisitionEntriesQuery->innerJoinRequisition()->whereAdd("Requisition." . Requisition::ID_DESTINATION_COUNTRY, $post["id_destination_country"]);
     }
     // Filter all requisition entries with a supplier default or a bentchmarcking that equal to id_supplier filter param
     if ($post["id_supplier"] != "") {
         $requisitionEntriesQuery->innerJoinKeyMotherSupplierBudget()->whereAdd("KeyMotherSupplierBudget." . KeyMotherSupplierBudget::ID_SUPPLIER, $post["id_supplier"]);
     }
     // Filter all requisition entries with a supplier default or a bentchmarcking that equal to id_supplier filter param
     if ($post["key_mother"] != "") {
         $requisitionEntriesQuery->whereAdd("RequisitionEntry." . RequisitionEntry::ID_PRODUCT, $post["key_mother"], RequisitionEntryQuery::LIKE);
     }
     if ($post["order"] == "date_asc" || $post["order"] == "date_desc") {
         $requisitionEntriesQuery->addAscendingOrderBy("RequisitionEntry." . RequisitionEntry::CREATION_DATE);
     } else {
         $requisitionEntriesQuery->addAscendingOrderBy("RequisitionEntry." . RequisitionEntry::ID_PRODUCT);
     }
     $requisitionEntries = $requisitionEntriesQuery->find();
     // If have more than 1 requisition entry then get extra info to requisition
     $parentKeys = array();
     $requisitions = new RequisitionCollection();
     $budgets = new KeyMotherSupplierBudgetCollection();
     if ($requisitionEntries->count() > 0) {
         $products = $products->filterByPks($requisitionEntries->getDistinctProducts())->orderByArrayPks($requisitionEntries->getDistinctProducts());
         $parentKeys = $products->getKeyMother();
         $requisitions = RequisitionQuery::create()->whereAdd(Requisition::ID_REQUISITION, $requisitionEntries->getDistinctRequisitions(), RequisitionQuery::IN)->find();
         if (count($parentKeys) > 0) {
             $budgets = KeyMotherSupplierBudgetQuery::create()->whereAdd(KeyMotherSupplierBudget::KEY_MOTHER, $parentKeys, KeyMotherSupplierBudgetQuery::IN)->actives()->find();
         }
     }
     // Proccess and group all requisition entries by parent key
     $requisitionEntriesGroupByParentKey = array();
     foreach ($parentKeys as $parentKey) {
         // Get all products belonging to current parent key
         $parentKeyProducts = $products->filterByKeyMother($parentKey);
         // Get all requisition entries belonging to products of a current parent key
         $parentKeyRequisitionEntries = $requisitionEntries->filterByIdProduct($parentKeyProducts->getPrimaryKeys());
         // Set Headers to group
         $requisitionEntriesGroupByParentKey[$parentKey]["header"]["parentKey"] = $parentKey;
         $requisitionEntriesGroupByParentKey[$parentKey]["header"]["description"] = $parentKeyProducts->current()->getItemName();
         $requisitionEntriesGroupByParentKey[$parentKey]["header"]["idDefaultProduct"] = $parentKeyProducts->current()->getItemCode();
         $requisitionEntriesGroupByParentKey[$parentKey]["header"]["firstRequisitionDate"] = $parentKeyRequisitionEntries->getFirstCreationDate();
         // Set a current supplier default name, in case of this don't have suppliers then set "-"
         if ($parentKeyRequisitionEntries->getRecurrentSupplierDefault() == null) {
             $requisitionEntriesGroupByParentKey[$parentKey]["header"]["supplierSapBussinessCode"] = "-";
         } else {
             $supplier = $suppliers->getByPK($parentKeyRequisitionEntries->getRecurrentSupplierDefault());
             if (!$supplier) {
                 $supplier = new SapSupplier();
             }
             $requisitionEntriesGroupByParentKey[$parentKey]["header"]["supplierSapBussinessCode"] = $supplier ? $supplier->getCardCode() : 'Error';
             $requisitionEntriesGroupByParentKey[$parentKey]["header"]["supplierName"] = $supplier->getName();
         }
         $requisitionEntriesGroupByParentKey[$parentKey]["header"]["totalQuantity"] = $parentKeyRequisitionEntries->getTotalQuantity();
         $requisitionEntriesGroupByParentKey[$parentKey]["header"]["targetPrice"] = $parentKeyProducts->current()->getCost();
         // Check if the min open price is less than target price, then set the lower of two
         if ($parentKeyProducts->current()->getCost() > 0) {
             $minPrice = $parentKeyProducts->current()->getCost() < $parentKeyRequisitionEntries->getMinOpenPrice() ? $parentKeyProducts->current()->getCost() : $parentKeyRequisitionEntries->getMinOpenPrice();
         } else {
             $minPrice = $parentKeyRequisitionEntries->getMinOpenPrice();
         }
         $requisitionEntriesGroupByParentKey[$parentKey]["header"]["minOpenPrice"] = $minPrice;
         $requisitionEntriesGroupByParentKey[$parentKey]["header"]["MOPTotalImport"] = $parentKeyRequisitionEntries->getTotalQuantity() * $minPrice;
         // Check if the parent key have budgets then set true or if it don't have budgets then set false
         $parentKeyBudgets = $budgets->filterByKeyMother($parentKey);
         $requisitionEntriesGroupByParentKey[$parentKey]["header"]["hasBudgets"] = $parentKeyBudgets->count() > 0 ? true : false;
         // Check if a key mother budget is autorized (prevent to no save more budgets when one key mother budget is autoprized)
         $requisitionEntriesGroupByParentKey[$parentKey]["header"]["hasAutorizedBudget"] = $parentKeyBudgets->checkAutorized();
         // Set all requisition entries of the parent key
         $requisitionEntriesGroupByParentKey[$parentKey]["requisitionEntries"] = $parentKeyRequisitionEntries;
         $requisitionEntriesGroupByParentKey[$parentKey]["autorizedBudget"] = $parentKeyBudgets->getAutorizedOrElse(new KeyMotherSupplierBudget());
     }
     if ($post["order"] == "date_desc") {
         $requisitionEntriesGroupByParentKey = array_reverse($requisitionEntriesGroupByParentKey);
     }
     // Assign all information to view
     $this->view->requisitions = $requisitions;
     $this->view->contentTitle = $this->i18n->_("Open Requisition by Item");
     $this->view->emptySupplier = new SapSupplier();
     $this->view->requisitionEntriesGroupByParentKey = $requisitionEntriesGroupByParentKey;
     $this->view->products = $products;
     $this->view->suppliers = $suppliers;
     $this->view->incoterms = array("" => $this->i18n->_("Select a Incoterm")) + IncotermQuery::create()->find()->toCombo();
     $this->view->currencies = $currencies = CurrencyQuery::create()->find();
     $this->view->currenciesToCombo = array("" => $this->i18n->_("Select a Currency")) + $currencies->toCombo();
     $this->view->status = array("" => $this->i18n->_("All")) + array_flip($allowedStatus);
     $this->view->allowedStatus = $allowedStatus;
     $this->view->countries = array("" => $this->i18n->_("All")) + CountryQuery::create()->find()->toCombo();
     $this->view->forwarders = array("" => $this->i18n->_("Select a Forwarder")) + ForwarderQuery::create()->actives()->find()->toCombo();
     $this->view->special = Requisition::$Type['Quick'];
     $this->view->portsCustom = array("" => $this->i18n->_("Select a Port Custom"));
     $this->view->courtyards = array("" => $this->i18n->_("Select a Courtyard"));
     $this->view->order = array("" => $this->i18n->_("Select a Order"), "date_asc" => $this->i18n->_("By First Date"), "date_desc" => $this->i18n->_("By Last Date"), "product" => $this->i18n->_("By Product"));
     $this->view->setTpl("Entries");
 }
 public function exportToExcelByDateAction()
 {
     $filters = $this->getRequest()->getParams();
     $programmedPaymentManager = new ProgrammedPaymentManager();
     $payments = $programmedPaymentManager->getProgrammedPayments($filters);
     $condensedProgrammedPayments = $programmedPaymentManager->getCondensedProgrammedPayments($payments);
     $suppliers = $programmedPaymentManager->getSuppliers($payments);
     $dates = $condensedProgrammedPayments->getDatesAndIndex("asc");
     foreach ($dates as $date) {
         $pay = $condensedProgrammedPayments->getByPK($date["index"]);
         $supplier = $suppliers->getByPK($pay->getIdSupplier());
         if (!$supplier instanceof SapSupplier) {
             $supplier = new SapSupplier();
         }
         $data[$i] = array(0 => $paymentArray[$pay->getIdSupplier()][$pay->getCurrency()][0] = $pay->getDueDateAsZendDate() instanceof \Zend_Date ? $pay->getDueDateAsZendDate()->get("yyyy-MM-dd") : $pay->getDueDate(), 1 => $paymentArray[$pay->getIdSupplier()][$pay->getCurrency()][1] = $pay->getTypeName(), 2 => $paymentArray[$pay->getIdSupplier()][$pay->getCurrency()][2] = $pay->getSapDocnum(), 3 => $paymentArray[$pay->getIdSupplier()][$pay->getCurrency()][3] = $supplier->getIndex(), 4 => $paymentArray[$pay->getIdSupplier()][$pay->getCurrency()][4] = $supplier->getName(), 5 => $paymentArray[$pay->getIdSupplier()][$pay->getCurrency()][5] = $pay->getCurrency(), 6 => $paymentArray[$pay->getIdSupplier()][$pay->getCurrency()][6] = $pay->getAmmount(), 7 => $paymentArray[$pay->getIdSupplier()][$pay->getCurrency()][7] = $pay->getCredits(), 8 => $paymentArray[$pay->getIdSupplier()][$pay->getCurrency()][8] = $pay->getPendingBalance());
         $i++;
     }
     $header = array($this->i18n->_('Due Date'), $this->i18n->_('Document'), $this->i18n->_('Document Number'), $this->i18n->_('Card Code'), $this->i18n->_('Name'), $this->i18n->_('Currency'), $this->i18n->_('Debits'), $this->i18n->_('Credits'), $this->i18n->_('Pending Balance'));
     $title = $this->i18n->_('Programmed Payment Report (by Date)');
     $fileName = $this->i18n->_('programmed_payment_report');
     $report = new SimpleListReport();
     $report->setTableTitle($title);
     $report->setTableHeaders($header);
     $report->setTableContent($data);
     $report->setFilename($fileName);
     $report->createSpreadsheet();
 }
示例#3
0
文件: Sample.php 项目: Eximagen/sochi
 /**
  * 
  * @param NpdSheet $npd
  * @param SapSupplier $supplier
  * @param Color $color
  * @return array
  */
 public function toArrayForList()
 {
     if (!empty($this->idNpdSheet)) {
         $npd = NpdSheetQuery::create()->findByPK($this->getIdNpdSheet());
     }
     if (!$npd instanceof NpdSheet) {
         $npd = new NpdSheet();
     }
     if (!empty($this->idSupplier)) {
         $supplier = SapSupplierQuery::create()->findByPK($this->getIdSupplier());
     }
     if (!$supplier instanceof SapSupplier) {
         $supplier = new SapSupplier();
     }
     if (!empty($this->idColor)) {
         $color = ColorQuery::create()->findByPK($this->getIdColor());
     }
     if (!$color instanceof Color) {
         $color = new Color();
     }
     return array('npd_status' => $npd->getStatusName(), 'name' => utf8_encode($npd->getName()), 'reference' => utf8_encode($npd->getReference()), 'supplier' => utf8_encode($supplier->getName()), 'color' => utf8_encode($color->getName()), 'id_sample' => $this->getIdSample(), 'id_npd_sheet' => $this->getIdNpdSheet(), 'quantity' => $this->getQuantity(), 'folio' => $this->getFolio(), 'notes' => utf8_encode($this->getNotes()), 'status' => $this->getStatus(), 'status_name' => $this->getStatusName(), 'deadline' => $this->getDeadline(), 'shipped_quantity' => $this->getShippedQuantity(), 'is_ordered' => $this->isOrdered(), 'is_requested_to_supplier' => $this->isRequestedToSupplier(), 'is_sent' => $this->isSent());
 }