Ejemplo n.º 1
0
 /**
  * Sending the email out
  *
  * @param unknown $sender
  * @param unknown $param
  *
  * @throws Exception
  */
 public function sendEmail($sender, $param)
 {
     $results = $errors = array();
     try {
         Dao::beginTransaction();
         if (!isset($param->CallbackParameter->orderId) || !($order = Order::get($param->CallbackParameter->orderId)) instanceof Order) {
             throw new Exception('System Error: invalid order provided!');
         }
         if (!isset($param->CallbackParameter->emailAddress) || ($emailAddress = trim($param->CallbackParameter->emailAddress)) === '') {
             throw new Exception('System Error: invalid emaill address provided!');
         }
         $emailBody = '';
         if (isset($param->CallbackParameter->emailBody) && ($emailBody = trim($param->CallbackParameter->emailBody)) !== '') {
             $emailBody = str_replace("\n", "<br />", $emailBody);
         }
         $pdfFile = EntityToPDF::getPDF($order);
         $asset = Asset::registerAsset($order->getOrderNo() . '.pdf', file_get_contents($pdfFile), Asset::TYPE_TMP);
         $type = $order->getType();
         EmailSender::addEmail('*****@*****.**', $emailAddress, 'BudgetPC ' . $type . ':' . $order->getOrderNo(), (trim($emailBody) === '' ? '' : $emailBody . "<br /><br />") . 'Please find attached ' . $type . ' (' . $order->getOrderNo() . '.pdf) from Budget PC Pty Ltd.', array($asset));
         $order->addComment('An email sent to "' . $emailAddress . '" with the attachment: ' . $asset->getAssetId(), Comments::TYPE_SYSTEM);
         $results['item'] = $order->getJson();
         Dao::commitTransaction();
     } catch (Exception $ex) {
         Dao::rollbackTransaction();
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Ejemplo n.º 2
0
 /**
  * (non-PHPdoc)
  * @see BPCPageAbstract::onLoad()
  */
 public function onLoad($param)
 {
     parent::onLoad($param);
     if (!$this->isPostBack) {
         $this->order = Order::get($this->Request['orderId']);
         if (!$this->order instanceof Order) {
             die('Invalid Order!');
         }
         if (isset($_REQUEST['pdf']) && intval($_REQUEST['pdf']) === 1) {
             $file = EntityToPDF::getPDF($this->order, 'docket');
             header('Content-Type: application/pdf');
             // The PDF source is in original.pdf
             readfile($file);
             die;
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * (non-PHPdoc)
  * @see BPCPageAbstract::onLoad()
  */
 public function onLoad($param)
 {
     parent::onLoad($param);
     if (!$this->isPostBack) {
         $this->kit = Kit::get($this->Request['kitId']);
         if (!$this->kit instanceof Kit) {
             die('Invalid Kit!');
         }
         if (isset($_REQUEST['pdf']) && intval($_REQUEST['pdf']) === 1) {
             $file = EntityToPDF::getPDF($this->kit);
             header('Content-Type: application/pdf');
             // The PDF source is in original.pdf
             readfile($file);
             die;
         }
         if (isset($_REQUEST['printlater']) && intval($_REQUEST['printlater']) === 1) {
             $this->getClientScript()->registerEndScript('printlater', 'window.print();');
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * saveOrder
  *
  * @param unknown $sender
  * @param unknown $param
  *
  * @throws Exception
  *
  */
 public function saveOrder($sender, $param)
 {
     $results = $errors = array();
     $daoStart = false;
     try {
         Dao::beginTransaction();
         $daoStart = true;
         $supplier = Supplier::get(trim($param->CallbackParameter->supplier->id));
         if (!$supplier instanceof Supplier) {
             throw new Exception('Invalid Supplier passed in!');
         }
         $supplierContactName = trim($param->CallbackParameter->supplier->contactName);
         $supplierContactNo = trim($param->CallbackParameter->supplier->contactNo);
         $supplierEmail = trim($param->CallbackParameter->supplier->email);
         if (!empty($supplierContactName) && $supplierContactName !== $supplier->getContactName()) {
             $supplier->setContactName($supplierContactName);
         }
         if (!empty($supplierContactNo) && $supplierContactNo !== $supplier->getContactNo()) {
             $supplier->setContactNo($supplierContactNo);
         }
         if (!empty($supplierEmail) && $supplierEmail !== $supplier->getEmail()) {
             $supplier->setEmail($supplierEmail);
         }
         $supplier->save();
         $purchaseOrder = PurchaseOrder::create($supplier, trim($param->CallbackParameter->supplierRefNum), $supplierContactName, $supplierContactNo, StringUtilsAbstract::getValueFromCurrency(trim($param->CallbackParameter->shippingCost)), StringUtilsAbstract::getValueFromCurrency(trim($param->CallbackParameter->handlingCost)))->setTotalAmount(StringUtilsAbstract::getValueFromCurrency(trim($param->CallbackParameter->totalPaymentDue)))->setEta(trim($param->CallbackParameter->eta))->setStatus(PurchaseOrder::STATUS_NEW)->save()->addComment(trim($param->CallbackParameter->comments), Comments::TYPE_PURCHASING);
         foreach ($param->CallbackParameter->items as $item) {
             if (!($product = Product::get(trim($item->productId))) instanceof Product) {
                 throw new Exception('Invalid Product passed in!');
             }
             $purchaseOrder->addItem($product, StringUtilsAbstract::getValueFromCurrency(trim($item->unitPrice)), intval(trim($item->qtyOrdered)));
         }
         if ($param->CallbackParameter->submitToSupplier === true) {
             $purchaseOrder->setStatus(PurchaseOrder::STATUS_ORDERED)->save();
         }
         $daoStart = false;
         Dao::commitTransaction();
         $results['item'] = $purchaseOrder->getJson();
         if (isset($param->CallbackParameter->confirmEmail) && trim($confirmEmail = trim($param->CallbackParameter->confirmEmail)) !== '') {
             $pdfFile = EntityToPDF::getPDF($purchaseOrder);
             $asset = Asset::registerAsset($purchaseOrder->getPurchaseOrderNo() . '.pdf', file_get_contents($pdfFile), Asset::TYPE_TMP);
             EmailSender::addEmail('*****@*****.**', $confirmEmail, 'BudgetPC Purchase Order:' . $purchaseOrder->getPurchaseOrderNo(), 'Please Find the attached PurchaseOrder(' . $purchaseOrder->getPurchaseOrderNo() . ') from BudgetPC.', array($asset));
             EmailSender::addEmail('*****@*****.**', '*****@*****.**', 'BudgetPC Purchase Order:' . $purchaseOrder->getPurchaseOrderNo(), 'Please Find the attached PurchaseOrder(' . $purchaseOrder->getPurchaseOrderNo() . ') from BudgetPC.', array($asset));
             $purchaseOrder->addComment('An email sent to "' . $confirmEmail . '" with the attachment: ' . $asset->getAssetId(), Comments::TYPE_SYSTEM);
         }
     } catch (Exception $ex) {
         if ($daoStart === true) {
             Dao::rollbackTransaction();
         }
         $errors[] = $ex->getMessage() . "<pre>" . $ex->getTraceAsString() . "</pre>";
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Ejemplo n.º 5
0
 /**
  * saveOrder
  *
  * @param unknown $sender
  * @param unknown $param
  *
  * @throws Exception
  *
  */
 public function saveOrder($sender, $param)
 {
     $results = $errors = array();
     try {
         Dao::beginTransaction();
         if (!($purchaseOrder = PurchaseOrder::get(trim($param->CallbackParameter->id))) instanceof PurchaseOrder) {
             throw new Exception('Invalid Purchase Order passed in!');
         }
         if (!($supplier = Supplier::get(trim($param->CallbackParameter->supplierId))) instanceof Supplier) {
             throw new Exception('Invalid Supplier passed in!');
         }
         $isSubmit = isset($param->CallbackParameter->isSubmit) && intval($param->CallbackParameter->isSubmit) === 1 ? true : false;
         $supplierRefNum = trim($param->CallbackParameter->supplierRefNum);
         $supplierContactName = trim($param->CallbackParameter->contactName);
         $supplierContactNo = trim($param->CallbackParameter->contactNo);
         $shippingCost = trim($param->CallbackParameter->shippingCost);
         $handlingCost = trim($param->CallbackParameter->handlingCost);
         $comment = trim($param->CallbackParameter->comments);
         $status = trim($param->CallbackParameter->status);
         $purchaseOrderTotalAmount = trim($param->CallbackParameter->totalAmount);
         $purchaseOrderTotalPaid = trim($param->CallbackParameter->totalPaid);
         $purchaseOrder->setTotalAmount($purchaseOrderTotalAmount)->setTotalPaid($purchaseOrderTotalPaid)->setSupplierRefNo($supplierRefNum)->setSupplierContact($supplierContactName)->setSupplierContactNumber($supplierContactNo)->setshippingCost($shippingCost)->sethandlingCost($handlingCost)->setStatus($status)->save();
         $purchaseOrder->addComment($comment, Comments::TYPE_PURCHASING);
         foreach ($param->CallbackParameter->items as $item) {
             $productUnitPrice = trim($item->unitPrice);
             $qtyOrdered = trim($item->qtyOrdered);
             $productTotalPrice = trim($item->totalPrice);
             if (!($product = Product::get(trim($item->productId))) instanceof Product) {
                 throw new Exception('Invalid Product passed in!');
             }
             if (!isset($item->id) || trim($item->id) === '') {
                 $poItem = null;
                 $purchaseOrder->addItem($product, $productUnitPrice, $qtyOrdered, '', '', $productTotalPrice, $poItem);
             } else {
                 if (($poItem = PurchaseOrderItem::get($item->id)) instanceof PurchaseOrderItem) {
                     $poItem->setProduct($product)->setUnitPrice($productUnitPrice)->setTotalPrice($productTotalPrice)->setQty($qtyOrdered);
                 }
             }
             $poItem->setActive(intval($item->active) === 1)->save();
         }
         $results['item'] = $purchaseOrder->getJson();
         if ($isSubmit === true) {
             $pdfFile = EntityToPDF::getPDF($purchaseOrder);
             $confirmEmail = trim($param->CallbackParameter->contactEmail);
             $asset = Asset::registerAsset($purchaseOrder->getPurchaseOrderNo() . '.pdf', file_get_contents($pdfFile), Asset::TYPE_TMP);
             EmailSender::addEmail('*****@*****.**', $confirmEmail, 'BudgetPC Purchase Order:' . $purchaseOrder->getPurchaseOrderNo(), 'Please Find the attached PurchaseOrder(' . $purchaseOrder->getPurchaseOrderNo() . ') from BudgetPC.', array($asset));
             EmailSender::addEmail('*****@*****.**', '*****@*****.**', 'BudgetPC Purchase Order:' . $purchaseOrder->getPurchaseOrderNo(), 'Please Find the attached PurchaseOrder(' . $purchaseOrder->getPurchaseOrderNo() . ') from BudgetPC.', array($asset));
             $purchaseOrder->addComment('An email sent to "' . $confirmEmail . '" with the attachment: ' . $asset->getAssetId(), Comments::TYPE_SYSTEM);
         }
         Dao::commitTransaction();
     } catch (Exception $ex) {
         Dao::rollbackTransaction();
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }