Exemplo n.º 1
0
 /**
  * (non-PHPdoc)
  * @see StaticsPageAbstract::getData()
  */
 public function getData($sender, $param)
 {
     $results = $errors = array();
     try {
         $dateFrom = trim($param->CallbackParameter->dateRange->from);
         $dateTo = trim($param->CallbackParameter->dateRange->to);
         $step = trim($param->CallbackParameter->dateRange->step);
         $showPrice = $param->CallbackParameter->showPrice;
         $timeRange = $this->_getXnames($dateFrom, $dateTo, $step);
         $names = array_keys($timeRange);
         $productIds = $param->CallbackParameter->productIds;
         if (count($productIds) === 0) {
             $productIds = $this->_topProductIds();
         }
         $series = array();
         foreach ($productIds as $pid) {
             $data = array_fill(0, count($names), 0);
             $name = 'Invalid Pid=' . $pid;
             if (($product = Product::get($pid)) instanceof Product) {
                 $name = $product->getSku();
                 $data = $this->_getSeries($timeRange, $dateFrom, $dateTo, array($product->getId()), $showPrice);
             }
             $series[] = array('name' => $name, 'data' => $data);
         }
         $results = array('chart' => array('type' => 'line'), 'title' => array('text' => 'Product Sales Trend', 'x' => -20), 'subtitle' => array('text' => 'Data is based on date range between "' . $dateFrom . '" to "' . $dateTo . '"', 'x' => -20), 'xAxis' => array('categories' => $names), 'yAxis' => array('title' => array('text' => $showPrice === true ? 'Order Amount ($)' : 'Ordered Qty')), 'series' => $series);
     } catch (Exception $ex) {
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Exemplo n.º 2
0
 /**
  *
  * @param unknown $sender
  * @param unknown $params
  */
 public function addComments($sender, $params)
 {
     $results = $errors = array();
     try {
         Dao::beginTransaction();
         if (!isset($params->CallbackParameter->entityName) || ($entityName = trim($params->CallbackParameter->entityName)) === '') {
             throw new Exception('System Error: EntityName is not provided!');
         }
         if (!isset($params->CallbackParameter->entityId) || ($entityId = trim($params->CallbackParameter->entityId)) === '') {
             throw new Exception('System Error: entityId is not provided!');
         }
         if (!($entity = $entityName::get($entityId)) instanceof $entityName) {
             throw new Exception('System Error: no such a entity exisits!');
         }
         if (!isset($params->CallbackParameter->comments) || ($comments = trim($params->CallbackParameter->comments)) === '') {
             throw new Exception('System Error: invalid comments passed in!');
         }
         $comment = Comments::addComments($entity, $comments, Comments::TYPE_NORMAL);
         $results['item'] = $comment->getJson();
         Dao::commitTransaction();
     } catch (Exception $ex) {
         Dao::rollbackTransaction();
         $errors[] = $ex->getMessage();
     }
     $params->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Exemplo n.º 3
0
 public function getLatestETAs($sender, $param)
 {
     $result = $error = array();
     try {
         $pageNo = $this->pageNumber;
         $pageSize = $this->pageSize;
         if (isset($param->CallbackParameter->pagination)) {
             $pageNo = $param->CallbackParameter->pagination->pageNo;
             $pageSize = $param->CallbackParameter->pagination->pageSize;
         }
         $notSearchStatusIds = array(OrderStatus::ID_CANCELLED, OrderStatus::ID_PICKED, OrderStatus::ID_SHIPPED);
         OrderItem::getQuery()->eagerLoad('OrderItem.order', 'inner join', 'ord', 'ord.id = ord_item.orderId and ord.active = 1');
         $stats = array();
         $oiArray = OrderItem::getAllByCriteria("(eta != '' and eta IS NOT NULL and eta != ? and ord.statusId not in (" . implode(',', $notSearchStatusIds) . "))", array(trim(UDate::zeroDate())), true, $pageNo, $pageSize, array("ord_item.eta" => "ASC", "ord_item.orderId" => "DESC"), $stats);
         $result['pagination'] = $stats;
         $result['items'] = array();
         foreach ($oiArray as $oi) {
             if (!$oi->getProduct() instanceof product) {
                 continue;
             }
             $tmp['eta'] = trim($oi->getEta());
             $tmp['orderNo'] = $oi->getOrder()->getOrderNo();
             $tmp['sku'] = $oi->getProduct() instanceof Product ? $oi->getProduct()->getSku() : '';
             $tmp['productName'] = $oi->getProduct()->getName();
             $tmp['id'] = $oi->getId();
             $tmp['orderId'] = $oi->getOrder()->getId();
             $result['items'][] = $tmp;
         }
     } catch (Exception $ex) {
         $error[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($result, $error);
 }
Exemplo n.º 4
0
 /**
  * (non-PHPdoc)
  * @see DetailsPageAbstract::saveItem()
  */
 public function saveItem($sender, $param)
 {
     $results = $errors = array();
     try {
         Dao::beginTransaction();
         if (!isset($param->CallbackParameter->id)) {
             throw new Exception('Invalid supplier ID passed in!');
         }
         $supplier = ($id = trim($param->CallbackParameter->id)) === '' ? new Supplier() : Supplier::get($id);
         if (!$supplier instanceof Supplier) {
             throw new Exception('Invalid supplier passed in!');
         }
         $contactName = trim($param->CallbackParameter->address->contactName);
         $contactNo = trim($param->CallbackParameter->address->contactNo);
         $street = trim($param->CallbackParameter->address->street);
         $city = trim($param->CallbackParameter->address->city);
         $region = trim($param->CallbackParameter->address->region);
         $postCode = trim($param->CallbackParameter->address->postCode);
         $country = trim($param->CallbackParameter->address->country);
         $address = $supplier->getAddress();
         $supplier->setName(trim($param->CallbackParameter->name))->setDescription(trim($param->CallbackParameter->description))->setContactNo(trim($param->CallbackParameter->contactNo))->setEmail(trim($param->CallbackParameter->email))->setAddress(Address::create($street, $city, $region, $country, $postCode, $contactName, $contactNo, $address))->save();
         $results['url'] = '/supplier/' . $supplier->getId() . '.html' . (isset($_REQUEST['blanklayout']) ? '?blanklayout=' . $_REQUEST['blanklayout'] : '');
         $results['item'] = $supplier->getJson();
         Dao::commitTransaction();
     } catch (Exception $ex) {
         Dao::rollbackTransaction();
         $errors[] = $ex->getMessage() . $ex->getTraceAsString();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Exemplo n.º 5
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);
 }
Exemplo n.º 6
0
 public function updateSetting($sender, $param)
 {
     $result = $errors = array();
     try {
         $result = $products = array();
         $systemSetting = SystemSettings::getByType(SystemSettings::TYPE_SYSTEM_BUILD_PRODUCTS_ID);
         foreach ($param->CallbackParameter as $type => $ids) {
             $result[$type] = array();
             $products[$type] = array();
             foreach ($ids as $index => $id) {
                 $id = intval(trim($id));
                 if (($product = Product::get($id)) instanceof Product) {
                     $result[$type][] = $id;
                     $products[$type][] = $product->getJson();
                 }
             }
         }
         Dao::beginTransaction();
         $systemSetting->setValue(json_encode($result))->save();
         Dao::commitTransaction();
     } catch (Exception $ex) {
         // 			Dao::rollbackTransaction();
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($products, $errors);
 }
Exemplo n.º 7
0
 /**
  * (non-PHPdoc)
  * @see StaticsPageAbstract::getData()
  */
 public function getData($sender, $param)
 {
     $results = $errors = array();
     try {
         $timeRange = $this->_getXnames();
         $names = array_keys($timeRange);
         $series = array();
         $series[] = array('name' => 'All', 'data' => $this->_getSeries($timeRange, $timeRange[$names[0]]['from'], $timeRange[$names[count($names) - 1]]['to']));
         foreach (OrderStatus::getAll() as $status) {
             $series[] = array('name' => $status->getName(), 'data' => $this->_getSeries($timeRange, $timeRange[$names[0]]['from'], $timeRange[$names[count($names) - 1]]['to'], array($status->getId())));
         }
         $results = array('chart' => array('type' => 'line'), 'title' => array('text' => 'BPC: Monthly Order Trend', 'x' => -20), 'subtitle' => array('text' => 'This is just order trend from last 12 month', 'x' => -20), 'xAxis' => array('categories' => $names), 'yAxis' => array('title' => array('text' => 'No of Orders')), 'series' => $series);
     } catch (Exception $ex) {
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Exemplo n.º 8
0
 /**
  * Run
  */
 public function run()
 {
     //   		if(!($this->getUser()->getUserAccount() instanceof UserAccount))
     //   			die (BPCPageAbstract::show404Page('Invalid request',"No defined access."));
     $results = $errors = array();
     try {
         $method = '_' . (isset($this->Request['method']) && trim($this->Request['method']) !== '' ? trim($this->Request['method']) : '');
         if (!method_exists($this, $method)) {
             throw new Exception('No such a method: ' . $method . '!');
         }
         $results = $this->{$method}($_REQUEST);
     } catch (Exception $ex) {
         $errors[] = $ex->getMessage();
     }
     $this->getResponse()->flush();
     $this->getResponse()->appendHeader('Content-Type: application/json');
     $this->getResponse()->write(StringUtilsAbstract::getJson($results, $errors));
 }
Exemplo n.º 9
0
 public function changePersonInfo($sender, $param)
 {
     $results = $errors = array();
     try {
         if (!isset($param->CallbackParameter->firstName) || ($firstName = trim($param->CallbackParameter->firstName)) === '') {
             throw new Exception("Invalid firstName!");
         }
         if (!isset($param->CallbackParameter->lastName) || ($lastName = trim($param->CallbackParameter->lastName)) === '') {
             throw new Exception("Invalid lastName!");
         }
         Core::getUser()->getPerson()->setFirstName($firstName)->setLastName($lastName)->save();
         Core::setUser(UserAccount::get(Core::getUser()->getId()), Core::getRole());
         $results['succ'] = true;
     } catch (Exception $ex) {
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Exemplo n.º 10
0
 /**
  * (non-PHPdoc)
  * @see StaticsPageAbstract::getData()
  */
 public function getData($sender, $param)
 {
     $results = $errors = array();
     try {
         $dateFrom = trim($param->CallbackParameter->dateRange->from);
         $dateTo = trim($param->CallbackParameter->dateRange->to);
         if (!($product = Product::get($param->CallbackParameter->productId)) instanceof Product) {
             throw new Exception('Invalid product id=' . $param->CallbackParameter->productId . ' provided');
         }
         $series = array();
         $series[] = array('name' => 'Sales Unit Price (incl. GST)', 'data' => $this->_getSalesSeries($product->getId(), $dateFrom, $dateTo));
         $series[] = array('name' => 'Purchase Unit Price (incl. GST)', 'data' => $this->_getPurchaseSeries($product->getId(), $dateFrom, $dateTo));
         $results = array('chart' => array('type' => 'spline'), 'title' => array('text' => 'Product Price($) Trend', 'x' => -20), 'subtitle' => array('text' => 'Data is based on date range between "' . $dateFrom . '" to "' . $dateTo . '"', 'x' => -20), 'xAxis' => array('type' => 'datetime', 'dateTimeLabelFormats' => array('month' => '%e. %b', 'year' => '%b'), 'title' => array('text' => 'Date')), 'yAxis' => array('title' => array('text' => 'Price($)'), 'min' => 0), 'tooltip' => array('headerFormat' => '<b>{series.name}</b><br>', 'pointFormat' => '{point.x:%e. %b}: ${point.y:.2f}'), 'series' => $series);
     } catch (Exception $ex) {
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Exemplo n.º 11
0
 /**
  * Creating a new Memo
  *
  * @param unknown $sender
  * @param unknown $params
  *
  * @throws Exception
  */
 public function addMemo($sender, $param)
 {
     $results = $errors = array();
     try {
         Dao::beginTransaction();
         if (!isset($param->CallbackParameter->entity) || !isset($param->CallbackParameter->entityId) || ($entityName = trim($param->CallbackParameter->entity)) === '' || !($entity = $entityName::get(trim($param->CallbackParameter->entityId))) instanceof $entityName) {
             throw new Exception('System Error: no entity provided for the Memo');
         }
         if (!isset($param->CallbackParameter->data) || !isset($param->CallbackParameter->data->comments) || ($comments = trim($param->CallbackParameter->data->comments)) === '') {
             throw new Exception('You can NOT create a Memo with a blank message.');
         }
         $newComments = null;
         $entity->addComment($comments, Comments::TYPE_MEMO, '', $newComments);
         $results['item'] = $newComments->getJson();
         Dao::commitTransaction();
     } catch (Exception $ex) {
         Dao::rollbackTransaction();
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Exemplo n.º 12
0
 public function getAllPricesForProduct($sender, $param)
 {
     $result = $errors = $outputArray = $finalOutputArray = array();
     try {
         if (!isset($param->CallbackParameter->sku) || ($sku = trim($param->CallbackParameter->sku)) === '') {
             throw new Exception('No SKU to search on!');
         }
         if (!isset($param->CallbackParameter->companyAliases) || count($companyAliases = json_decode(json_encode($param->CallbackParameter->companyAliases), true)) === 0) {
             throw new Exception('No companyAliases to search on!');
         }
         if (!isset($param->CallbackParameter->price) || ($myPrice = str_replace(' ', '', $param->CallbackParameter->price)) === '') {
             $myPrice = 0;
         } else {
             if (!is_numeric($myPrice = str_replace('$', '', str_replace(',', '', $myPrice)))) {
                 throw new Exception('No provided my price is NOT a number(=' . $myPrice . '!');
             }
         }
         $result['item'] = PriceMatcher::getPrices($companyAliases, $sku, $myPrice);
     } catch (Exception $ex) {
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($result, $errors);
 }
Exemplo n.º 13
0
    /**
     * Getting the items
     *
     * @param unknown $sender
     * @param unknown $param
     * @throws Exception
     *
     */
    public function getItems($sender, $param)
    {
        $results = $errors = array();
        try {
            if (!isset($param->CallbackParameter->searchCriteria->supplierId) || !($supplier = Supplier::get(trim($param->CallbackParameter->searchCriteria->supplierId))) instanceof Supplier) {
                throw new Exception('Invalid Supplier provided');
            }
            if (!isset($param->CallbackParameter->searchCriteria->invoiceNo) || ($invoiceNo = trim($param->CallbackParameter->searchCriteria->invoiceNo)) === '') {
                throw new Exception('Invalid Invoice number provided');
            }
            ReceivingItem::getQuery()->eagerLoad('ReceivingItem.purchaseOrder', 'inner join', 'rec_item_po', 'rec_item_po.id = rec_item.purchaseOrderId');
            if (ReceivingItem::countByCriteria('rec_item_po.supplierId = ? and rec_item.invoiceNo = ?', array($supplier->getId(), $invoiceNo)) === 0) {
                throw new Exception('There is no such a invoice(invoice No=' . $invoiceNo . ') for supplier:' . $supplier->getName());
            }
            $sql = 'select ri.productId,
						ri.unitPrice `unitPrice`,
						sum(ri.qty) `qty`,
						group_concat(distinct ri.id) `itemIds`,
						group_concat(distinct po.id) `poIds`
					from receivingitem ri
					inner join purchaseorder po on (po.id = ri.purchaseOrderId)
					where ri.active = 1 and ri.invoiceNo = ? and po.supplierId = ?
					group by ri.productId,  ri.unitPrice';
            $params = array($invoiceNo, $supplier->getId());
            $rows = Dao::getResultsNative($sql, $params);
            $results['supplier'] = $supplier->getJson();
            $results['items'] = array();
            foreach ($rows as $row) {
                $items = count($itemIds = explode(',', $row['itemIds'])) === 0 ? array() : ReceivingItem::getAllByCriteria('id in (' . implode(',', array_fill(0, count($itemIds), '?')) . ')', $itemIds);
                $pos = count($poIds = explode(',', $row['poIds'])) === 0 ? array() : PurchaseOrder::getAllByCriteria('id in (' . implode(',', array_fill(0, count($poIds), '?')) . ')', $poIds);
                $results['items'][] = array('product' => Product::get($row['productId'])->getJson(), 'totalQty' => $row['qty'], 'totalPrice' => $row['unitPrice'] * $row['qty'], 'items' => array_map(create_function('$a', 'return $a->getJson();'), $items), 'purchaseOrders' => array_map(create_function('$a', 'return $a->getJson();'), $pos));
            }
        } catch (Exception $ex) {
            $errors[] = $ex->getMessage();
        }
        $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
    }
Exemplo n.º 14
0
 /**
  * delete the items
  *
  * @param unknown $sender
  * @param unknown $param
  * @throws Exception
  *
  */
 public function deleteItems($sender, $param)
 {
     $results = $errors = array();
     try {
         $class = trim($this->_focusEntity);
         $ids = isset($param->CallbackParameter->ids) ? $param->CallbackParameter->ids : array();
         if (count($ids) > 0) {
             $parents = array();
             foreach ($ids as $id) {
                 if (!($item = $class::get($id)) instanceof $class) {
                     continue;
                 }
                 $item->setActive(false)->save();
                 $parents[] = $item->getParent()->getJson();
             }
             $class::deleteByCriteria('id in (' . str_repeat('?', count($ids)) . ')', $ids);
             $results['parents'] = $parents;
         }
     } catch (Exception $ex) {
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Exemplo n.º 15
0
 /**
  * save the items
  *
  * @param unknown $sender
  * @param unknown $param
  * @throws Exception
  *
  */
 public function saveItem($sender, $param)
 {
     $results = $errors = array();
     try {
         $class = trim($this->_focusEntity);
         if (!isset($param->CallbackParameter->item)) {
             throw new Exception("System Error: no item information passed in!");
         }
         $item = isset($param->CallbackParameter->item->id) && ($item = $class::get($param->CallbackParameter->item->id)) instanceof $class ? $item : null;
         $value = trim($param->CallbackParameter->item->value);
         if (!$item instanceof $class) {
             throw new Exception("System Error: Invalid id passed in");
         }
         $item->setValue($value)->save();
         $results['item'] = $item->getJson();
     } catch (Exception $ex) {
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
 public function deleteAliasForPriceMatchCompany($sender, $param)
 {
     $result = $error = array();
     try {
         if (!isset($param->CallbackParameter->data)) {
             throw new Exception('System Error: Noting to Delete!!!');
         }
         $data = $param->CallbackParameter->data;
         if (!isset($data->id) || !isset($data->companyAlias) || ($id = trim($data->id)) == '' || ($alias = trim($data->companyAlias)) == '') {
             throw new Exception('Data to be deleted is NOT proper format');
         }
         if (!($pmc = PriceMatchCompany::get($id)) instanceof PriceMatchCompany) {
             throw new Exception('Invalid Id [' . $id . '] provided for PriceMatchCompany!!!');
         }
         $result['items'] = $pmc->setActive(false)->save()->getJson();
     } catch (Exception $ex) {
         $error[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($result, $error);
 }
Exemplo n.º 17
0
 public function getAllCodeForProduct($sender, $param)
 {
     $result = $errors = $item = array();
     try {
         if (!isset($param->CallbackParameter->importDataTypes) || ($type = trim($param->CallbackParameter->importDataTypes)) === '' || ($type = trim($param->CallbackParameter->importDataTypes)) === 'Select a Import Type') {
             throw new Exception('Invalid upload type passed in!');
         }
         switch ($type) {
             case 'myob_ean':
                 $index = $param->CallbackParameter->index;
                 if (!isset($param->CallbackParameter->sku) || ($sku = trim($param->CallbackParameter->sku)) === '' || !($product = Product::getBySku($sku)) instanceof Product) {
                     throw new Exception('Invalid sku passed in! (line ' . $index . ')');
                 }
                 if (!isset($param->CallbackParameter->itemNo) || ($itemNo = trim($param->CallbackParameter->itemNo)) === '') {
                     throw new Exception('Invalid itemNo passed in! (line ' . $index . ')');
                 }
                 $result['path'] = 'product';
                 $productType = ProductCodeType::get(ProductCodeType::ID_EAN);
                 $item = $this->updateProductCode($product, $itemNo, $productType);
                 $result['item'] = $item->getJson();
                 break;
             case 'myob_upc':
                 $index = $param->CallbackParameter->index;
                 if (!isset($param->CallbackParameter->sku) || ($sku = trim($param->CallbackParameter->sku)) === '' || !($product = Product::getBySku($sku)) instanceof Product) {
                     throw new Exception('Invalid sku passed in! (line ' . $index . ')');
                 }
                 if (!isset($param->CallbackParameter->itemNo) || ($itemNo = trim($param->CallbackParameter->itemNo)) === '') {
                     throw new Exception('Invalid itemNo passed in! (line ' . $index . ')');
                 }
                 $result['path'] = 'product';
                 $productType = ProductCodeType::get(ProductCodeType::ID_UPC);
                 $item = $this->updateProductCode($product, $itemNo, $productType);
                 $result['item'] = $item->getJson();
                 break;
             case 'stockAdjustment':
                 $index = $param->CallbackParameter->index;
                 if (!isset($param->CallbackParameter->sku) || ($sku = trim($param->CallbackParameter->sku)) === '' || !($product = Product::getBySku($sku)) instanceof Product) {
                     throw new Exception('Invalid sku passed in! (line ' . $index . ')');
                 }
                 $result['path'] = 'product';
                 $item = $this->updateStocktack($product, trim($param->CallbackParameter->stockOnPO), trim($param->CallbackParameter->stockOnHand), trim($param->CallbackParameter->stockInRMA), trim($param->CallbackParameter->stockInParts), trim($param->CallbackParameter->totalInPartsValue), trim($param->CallbackParameter->totalOnHandValue), $param->CallbackParameter->active, trim($param->CallbackParameter->comment));
                 $result['item'] = $item->getJson();
                 break;
             case 'accounting':
                 $index = $param->CallbackParameter->index;
                 if (!isset($param->CallbackParameter->sku) || ($sku = trim($param->CallbackParameter->sku)) === '') {
                     throw new Exception('Invalid sku passed in! (line ' . $index . ')');
                 }
                 if (!($product = Product::getBySku($sku)) instanceof Product) {
                     $product = Product::create($sku, $sku);
                 }
                 $result['path'] = 'product';
                 $item = $this->updateAccountingInfo($product, trim($param->CallbackParameter->assetAccNo), trim($param->CallbackParameter->costAccNo), trim($param->CallbackParameter->revenueAccNo));
                 $result['item'] = $item->getJson();
                 break;
             case 'accountingCode':
                 $index = $param->CallbackParameter->index;
                 if (!isset($param->CallbackParameter->description) || ($description = trim($param->CallbackParameter->description)) === '') {
                     throw new Exception('Invalid description passed in! (line ' . $index . ')');
                 }
                 if (!isset($param->CallbackParameter->code) || ($code = trim($param->CallbackParameter->code)) === '' || !is_numeric($code)) {
                     throw new Exception('Invalid Code passed in! (line ' . $index . ')');
                 }
                 $result['path'] = '';
                 $item = $this->updateAccountingCode($description, $code);
                 $result['item'] = $item->getJson();
                 break;
             default:
                 throw new Exception('Invalid upload type passed in!');
         }
     } catch (Exception $ex) {
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($result, $errors);
 }
Exemplo n.º 18
0
 /**
  * toggleActive
  *
  * @param unknown $sender
  * @param unknown $param
  */
 public function toggleActive($sender, $param)
 {
     $results = $errors = array();
     try {
         $id = isset($param->CallbackParameter->productId) ? $param->CallbackParameter->productId : '';
         if (!($product = Product::get($id)) instanceof Product) {
             throw new Exception('Invalid product!');
         }
         $product->setActive(intval($param->CallbackParameter->active))->save();
         $results['item'] = $product->getJson();
     } catch (Exception $ex) {
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Exemplo n.º 19
0
 /**
  * updateInvoiceNo
  *
  * @param unknown $sender
  * @param unknown $param
  * @throws Exception
  *
  */
 public function updateInvoiceNo($sender, $param)
 {
     $results = $errors = array();
     try {
         if (!isset($param->CallbackParameter->supplierId) || !($supplier = Supplier::get(trim($param->CallbackParameter->supplierId))) instanceof Supplier) {
             throw new Exception('Invalid Supplier provided.');
         }
         if (!isset($param->CallbackParameter->newInoviceNo) || ($newInoviceNo = trim($param->CallbackParameter->newInoviceNo)) === '') {
             throw new Exception('Invalid newInoviceNo.');
         }
         if (!isset($param->CallbackParameter->oldInvoiceNo)) {
             throw new Exception('Invalid oldInvoiceNo.');
         }
         $oldInvoiceNo = trim($param->CallbackParameter->oldInvoiceNo);
         ReceivingItem::updateByCriteria('invoiceNo = :newInvoiceNo', 'invoiceNo = :oldInvoiceNo and purchaseOrderId in (select po.id from purchaseorder po where po.active = 1 and po.supplierId = :supplierId)', array('newInvoiceNo' => $newInoviceNo, 'oldInvoiceNo' => $oldInvoiceNo, 'supplierId' => $supplier->getId()));
     } catch (Exception $ex) {
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Exemplo n.º 20
0
 /**
  * Getting the items
  *
  * @param unknown $sender
  * @param unknown $param
  * @throws Exception
  *
  */
 public function actionTask($sender, $param)
 {
     $results = $errors = array();
     try {
         Dao::beginTransaction();
         if (!isset($param->CallbackParameter->taskId) || !($task = Task::get(trim($param->CallbackParameter->taskId))) instanceof Task) {
             throw new Exception('Invalid Task provided!');
         }
         if (!isset($param->CallbackParameter->method) || ($method = trim(trim($param->CallbackParameter->method))) === '' || !method_exists($task, $method)) {
             throw new Exception('Invalid Action Method!');
         }
         $comments = isset($param->CallbackParameter->comments) ? trim($param->CallbackParameter->comments) : '';
         $results['item'] = $task->{$method}(Core::getUser(), $comments)->getJson();
         Dao::commitTransaction();
     } catch (Exception $ex) {
         Dao::rollbackTransaction();
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Exemplo n.º 21
0
 /**
  * Getting the items
  *
  * @param unknown $sender
  * @param unknown $param
  * @throws Exception
  *
  */
 public function genReport($sender, $param)
 {
     $results = $errors = array();
     try {
         $searchParams = json_decode(json_encode($param->CallbackParameter), true);
         $wheres = $joins = $params = array();
         if (isset($searchParams['pro.name']) && ($name = trim($searchParams['pro.name'])) !== '') {
             $wheres[] = 'pro.name like :name';
             $params['name'] = '%' . $name . '%';
         }
         if (isset($searchParams['pro.active']) && ($active = trim($searchParams['pro.active'])) !== '') {
             $wheres[] = 'pro.active = :active';
             $params['active'] = $active;
         }
         $productIds = $this->_getParams($searchParams, 'pro.id');
         if (count($productIds) > 0) {
             $array = array();
             foreach ($productIds as $index => $productId) {
                 $key = 'product_' . $index;
                 $array[] = ':' . $key;
                 $params[$key] = $productId;
             }
             $wheres[] = 'pro.id in (' . implode(',', $array) . ')';
         }
         $manufacturerIds = $this->_getParams($searchParams, 'pro.manufacturerIds');
         if (count($manufacturerIds) > 0) {
             $array = array();
             foreach ($manufacturerIds as $index => $manufacturerId) {
                 $key = 'brand_' . $index;
                 $array[] = ':' . $key;
                 $params[$key] = $manufacturerId;
             }
             $wheres[] = 'pro.manufacturerId in (' . implode(',', $array) . ')';
         }
         $supplierIds = $this->_getParams($searchParams, 'pro.supplierIds');
         if (count($supplierIds) > 0) {
             $array = array();
             foreach ($supplierIds as $index => $supplierId) {
                 $key = 'supplier_' . $index;
                 $array[] = ':' . $key;
                 $params[$key] = $supplierId;
             }
             $joins[] = 'inner join suppliercode sup_code on (sup_code.productId = pro.id and sup_code.active = 1 and sup_code.supplierId in (' . implode(',', $array) . '))';
         }
         $productCategoryIds = $this->_getParams($searchParams, 'pro.productCategoryIds');
         if (count($productCategoryIds) > 0) {
             $array = array();
             foreach ($productCategoryIds as $index => $productCategoryId) {
                 $key = 'productCategory_' . $index;
                 $array[] = ':' . $key;
                 $params[$key] = $productCategoryId;
             }
             $joins[] = 'inner join product_category x on (x.productId = pro.id and x.active = 1 and x.categoryId in (' . implode(',', $array) . '))';
         }
         $sql = 'select pro.id `proId`, pro.sku `proSku`, pro.name `proName` from product pro ' . implode(' ', $joins) . (count($wheres) > 0 ? ' where ' . implode(' AND ', $wheres) : '');
         $result = Dao::getResultsNative($sql, $params, PDO::FETCH_ASSOC);
         if (count($result) === 0) {
             throw new Exception('No result found!');
         }
         $proIdMap = array();
         foreach ($result as $row) {
             $proIdMap[$row['proId']] = $row;
         }
         $rates = $this->_getRunRateData(array_keys($proIdMap));
         $ratesMap = array();
         foreach ($rates as $row) {
             $ratesMap[$row['proId']] = $row;
         }
         $data = array();
         foreach ($proIdMap as $productId => $productInfo) {
             if (!isset($ratesMap[$productId])) {
                 $data[$productId] = array_merge($productInfo, array('7days' => 0, '14days' => 0, '1month' => 0, '3month' => 0, '6month' => 0, '12month' => 0));
             } else {
                 $data[$productId] = array_merge($productInfo, $ratesMap[$productId]);
             }
         }
         if (!($asset = $this->_getExcel($data)) instanceof Asset) {
             throw new Exception('Failed to create a excel file');
         }
         $results['url'] = $asset->getUrl();
     } catch (Exception $ex) {
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Exemplo n.º 22
0
 /**
  * deactive a user
  * 
  * @param unknown $sender
  * @param unknown $params
  * 
  * @throws Exception
  */
 public function deleteUser($sender, $param)
 {
     $results = $errors = array();
     try {
         if (!isset($param->CallbackParameter->userId) || !($userAccount = UserAccount::get(trim($param->CallbackParameter->userId))) instanceof UserAccount) {
             throw new Exception("Invalid user account passed for deletion!");
         }
         $results = $userAccount->setActive(false)->save()->getJson();
     } catch (Exception $ex) {
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Exemplo n.º 23
0
 /**
  * Update the changeShippingMethod
  *
  * @param unknown $sender
  * @param unknown $param
  *
  * @throws Exception
  */
 public function changeShippingMethod($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->shippingMethod) || ($shippingMethod = trim($param->CallbackParameter->shippingMethod)) === '') {
             throw new Exception('System Error: invalid shippingMethod provided!');
         }
         $order->addInfo(OrderInfoType::ID_MAGE_ORDER_SHIPPING_METHOD, $shippingMethod, true)->save()->addComment($msg = 'Changed Shipping Method to "' . $shippingMethod . '"', Comments::TYPE_NORMAL)->addLog($msg, Log::TYPE_SYSTEM, '', __CLASS__ . '::' . __FUNCTION__);
         $results['item'] = $order->getJson();
         Dao::commitTransaction();
     } catch (Exception $ex) {
         Dao::rollbackTransaction();
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Exemplo n.º 24
0
 /**
  * delete the items
  *
  * @param unknown $sender
  * @param unknown $param
  * @throws Exception
  *
  */
 public function deleteItems($sender, $param)
 {
     $results = $errors = array();
     try {
         $class = trim($this->_focusEntity);
         $ids = isset($param->CallbackParameter->ids) ? $param->CallbackParameter->ids : array();
         if (count($ids) > 0) {
             $class::deleteByCriteria('id in (' . str_repeat('?', count($ids)) . ')', $ids);
         }
     } catch (Exception $ex) {
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Exemplo n.º 25
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);
 }
Exemplo n.º 26
0
 /**
  *
  * @param unknown $sender
  * @param unknown $params
  */
 public function addComments($sender, $params)
 {
     $results = $errors = array();
     try {
         Dao::beginTransaction();
         if (!isset($params->CallbackParameter->creditNote) || !($creditNote = CreditNote::get($params->CallbackParameter->creditNote->id)) instanceof CreditNote) {
             throw new Exception('System Error: invalid CreditNote passed in!');
         }
         if (!isset($params->CallbackParameter->comments) || ($comments = trim($params->CallbackParameter->comments)) === '') {
             throw new Exception('System Error: invalid comments passed in!');
         }
         $comment = Comments::addComments($creditNote, $comments, Comments::TYPE_NORMAL);
         $results = $comment->getJson();
         Dao::commitTransaction();
     } catch (Exception $ex) {
         Dao::rollbackTransaction();
         $errors[] = $ex->getMessage();
     }
     $params->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Exemplo n.º 27
0
 /**
  * save the items
  *
  * @param unknown $sender
  * @param unknown $param
  * @throws Exception
  *
  */
 public function saveItem($sender, $param)
 {
     $results = $errors = array();
     try {
         $class = trim($this->_focusEntity);
         if (!isset($param->CallbackParameter->item)) {
             throw new Exception("System Error: no item information passed in!");
         }
         $item = isset($param->CallbackParameter->item->id) && ($item = $class::get($param->CallbackParameter->item->id)) instanceof $class ? $item : null;
         $name = trim($param->CallbackParameter->item->name);
         $description = trim($param->CallbackParameter->item->description);
         if ($item instanceof $class) {
             $item->setName($name)->setDescription($description)->save();
         } else {
             $item = $class::create($name, $description, false);
         }
         $results['item'] = $item->getJson();
     } catch (Exception $ex) {
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Exemplo n.º 28
0
 /**
  * Getting the orders
  * 
  * @param unknown $sender
  * @param unknown $param
  * @throws Exception
  * 
  */
 public function getOrderItems($sender, $param)
 {
     $results = $errors = array();
     try {
         if (!isset($param->CallbackParameter->searchCriteria) || count($serachCriteria = json_decode(json_encode($param->CallbackParameter->searchCriteria), true)) === 0) {
             throw new Exception('System Error: search criteria not provided!');
         }
         $pageNo = 1;
         $pageSize = DaoQuery::DEFAUTL_PAGE_SIZE;
         if (isset($param->CallbackParameter->pagination)) {
             $pageNo = $param->CallbackParameter->pagination->pageNo;
             $pageSize = $param->CallbackParameter->pagination->pageSize;
         }
         $noSearch = true;
         $where = array(1);
         $params = array();
         foreach ($serachCriteria as $field => $value) {
             if (is_array($value) && count($value) === 0 || is_string($value) && ($value = trim($value)) === '') {
                 continue;
             }
             OrderItem::getQuery()->eagerLoad("OrderItem.order", 'inner join', 'ord', 'ord.id = ord_item.orderId');
             switch ($field) {
                 case 'ord.orderNo':
                 case 'ord.invNo':
                     $where[] = $field . " like ? ";
                     $params[] = $value . '%';
                     break;
                 case 'ord_item.isOrdered':
                     $where[] = $field . " = ? ";
                     $params[] = $value;
                     break;
                 case 'ord_item.eta.from':
                     $where[] = 'ord_item.eta >= ?';
                     $params[] = $value;
                     break;
                 case 'ord_item.eta.to':
                     $where[] = 'ord_item.eta <= ?';
                     $params[] = $value;
                     break;
             }
             $noSearch = false;
         }
         if ($noSearch === true) {
             throw new Exception("Nothing to search!");
         }
         $stats = array();
         $orderItems = OrderItem::getAllByCriteria(implode(' AND ', $where), $params, true, $pageNo, $pageSize, array('ord_item.eta' => 'asc', 'ord.orderNo' => 'asc'), $stats);
         $results['pageStats'] = $stats;
         $results['items'] = array();
         foreach ($orderItems as $item) {
             $orderItemArray = $item->getJson();
             $comments = Comments::getAllByCriteria('entityName = ? and entityId = ?', array('OrderItem', $item->getId()), true, null, DaoQuery::DEFAUTL_PAGE_SIZE, array('created' => 'desc'));
             $orderItemArray['comments'] = array_map(create_function('$a', 'return $a->getJson();'), $comments);
             $results['items'][] = $orderItemArray;
         }
     } catch (Exception $ex) {
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Exemplo n.º 29
0
 /**
  * deleteItem
  *
  * @param unknown $sender
  * @param unknown $param
  * @throws Exception
  *
  */
 public function deleteItem($sender, $param)
 {
     $results = $errors = array();
     try {
         Dao::beginTransaction();
         if (!isset($param->CallbackParameter->id) || !($recievingItem = ReceivingItem::get(trim($param->CallbackParameter->id))) instanceof ReceivingItem) {
             throw new Exception('System Error: invalid item provided');
         }
         $recievingItem->setActive(false)->save();
         $results['item'] = $recievingItem->getJson();
         Dao::commitTransaction();
     } catch (Exception $ex) {
         Dao::rollbackTransaction();
         $errors[] = $ex->getMessage();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }
Exemplo n.º 30
0
 /**
  * save the items
  *
  * @param unknown $sender
  * @param unknown $param
  * @throws Exception
  *
  */
 public function deactivateItems($sender, $param)
 {
     $results = $errors = array();
     try {
         $class = trim($this->_focusEntity);
         $id = isset($param->CallbackParameter->item_id) ? $param->CallbackParameter->item_id : array();
         $creditNote = CreditNote::get($id);
         if (!$creditNote instanceof CreditNote) {
             throw new Exception('Invalid Credit Note passed in');
         }
         $creditNote->setActive(false)->save();
         $results['item'] = $creditNote->getJson(array('order' => $creditNote->getOrder() instanceof Order ? '' : $creditNote->getOrder()->getJson(), 'customer' => $creditNote->getCustomer()->getJson()));
     } catch (Exception $ex) {
         $errors[] = $ex->getMessage() . $ex->getTraceAsString();
     }
     $param->ResponseData = StringUtilsAbstract::getJson($results, $errors);
 }