Пример #1
0
 public function run()
 {
     if (!isAppLoaded("purchase")) {
         $this->error(sprintf(lang("messages.unfoundApp"), "purchase"));
         return;
     }
     //跳转至生成采购单单据
     if (!IS_POST) {
         $this->response(array("type" => "redirect", "location" => sprintf("/doWorkflow/producePlan/makePurchase/%d/%d", $this->currentNode["id"], $this->mainrowId)));
     }
     $model = D("Purchase");
     $data = $_POST;
     unset($data["doNext"]);
     unset($data["id"]);
     $data["source_model"] = "ProducePlan";
     $data["source_id"] = $this->mainrowId;
     foreach ($data["rows"] as $k => $row) {
         unset($data["rows"][$k]["id"]);
         $data["rows"][$k]["amount"] = 0;
         $data["rows"][$k]["unit_price"] = 0;
     }
     $data = $model->formatData($data);
     $purchaseId = $model->newBill($data);
     $thePurchase = $model->find($purchaseId);
     $this->context["memo"] = $thePurchase["bill_id"];
 }
Пример #2
0
 public function run()
 {
     if (!isAppLoaded("outsourcing")) {
         $this->error(sprintf(lang("messages.unfoundApp"), "outsourcing"));
         return;
     }
 }
Пример #3
0
 public function run()
 {
     if (!isAppLoaded("finance")) {
         $this->error(sprintf(lang("messages.unfoundApp"), "finance"));
         return;
     }
     if (!IS_POST) {
         $this->leaveMessage();
     }
     $theOrder = D("Orders")->find($this->mainrowId);
     $data = array("subject" => lang("Orders"), "type_id" => getTypeIdByAlias("receive", "orders"), "customer_id" => $theOrder["customer_id"], "source_model" => "Orders", "source_id" => $this->mainrowId, "amount" => $theOrder["total_amount_real"], "memo" => $_POST["message"]);
     $model = D("FinanceReceivePlan");
     $model->record($data);
 }
Пример #4
0
 public function read()
 {
     if (!$_GET["includeRows"] or $_GET['workflow']) {
         return parent::read();
     }
     $this->readModel = "OrdersView";
     $formData = parent::read(true);
     $formData["inputTime"] = $formData["dateline"] * 1000;
     $rowModel = D("OrdersDetailView");
     $rows = $rowModel->where("OrdersDetail.order_id=" . $formData["id"])->select();
     $modelIds = array();
     $rowData = array();
     foreach ($rows as $v) {
         $tmp = explode(DBC("goods.unique.separator"), $v["factory_code_all"]);
         //根据factory_code_all factory_code - standard - version
         $factory_code = array_shift($tmp);
         $modelIds = array_merge($modelIds, $tmp);
         $v["modelIds"] = $tmp;
         $v["goods_id"] = sprintf("%s_%s_%s", $factory_code, $v["goods_id"], $v["goods_category_id"]);
         // factory_code, id, catid
         $v["goods_id_label"] = sprintf("%s", $v["goods_name"]);
         $rowData[$v["id"]] = $v;
     }
     $formData["customer_id_label"] = $formData["customer"];
     $dataModel = D("DataModelDataView");
     $rowData = $dataModel->assignModelData($rowData, $modelIds);
     $formData["rows"] = reIndex($rowData);
     if ($formData["tax_amount"]) {
         $formData["includeTax"] = true;
     }
     /*
      * 相关单据
      * **/
     $relateItem = array();
     $id = abs(intval($_GET["id"]));
     if (isAppLoaded("purchase")) {
         $relateItem = array_merge($relateItem, (array) D("Purchase")->toRelatedItem("Orders", $id));
     }
     if (isAppLoaded("finance")) {
         $relateItem = array_merge($relateItem, (array) D("FinanceReceivePlan")->toRelatedItem("Orders", $id));
     }
     if (isAppLoaded("produce")) {
         $relateItem = array_merge($relateItem, (array) D("ProducePlan")->toRelatedItem("Orders", $id));
     }
     $formData["relatedItems"] = $relateItem;
     $this->response($formData);
 }
Пример #5
0
 public function run()
 {
     if (!isAppLoaded("produce")) {
         $this->error(sprintf(lang("messages.unfoundApp"), "produce"));
         return;
     }
     if (!IS_POST) {
         $this->response(array("type" => "redirect", "location" => sprintf("/doWorkflow/orders/makeProduce-ProducePlan/%d/%d", $this->currentNode["id"], $this->mainrowId)));
     }
     $model = D("ProducePlan");
     $data = $_POST;
     unset($data["doNext"]);
     unset($data["id"]);
     $data["source_model"] = "Orders";
     $data["source_id"] = $this->mainrowId;
     foreach ($data["rows"] as $k => $row) {
         unset($data["rows"][$k]["id"]);
     }
     $data = $model->formatData($data);
     $planId = $model->newBill($data);
     $this->context["memo"] = "#" . $planId;
 }
Пример #6
0
 public function index()
 {
     $appConf = F("appConf");
     $appConf = $appConf[CURRENT_APP];
     $dateStart = strtotime(date("Y-m"));
     $dateEnd = CTS;
     if ($_GET["_filter_start_dateline"]) {
         $dateStart = strtotime($_GET["_filter_start_dateline"]);
     }
     if ($_GET["_filter_end_dateline"]) {
         $dateEnd = strtotime($_GET["_filter_end_dateline"]);
     }
     $limit = $this->beforeLimit();
     //库存信息
     $storeModel = D("StockProductList");
     $tmp = $storeModel->table(C("DB_PREFIX") . "stock_product_list StockProductList")->field("SUM(StockProductList.num) as store_num, goods_id, factory_code_all, Goods.name as goods_name, Goods.measure")->join(C("DB_PREFIX") . "goods Goods ON Goods.id=StockProductList.goods_id")->group("factory_code_all")->order("store_num DESC")->limit($limit)->select();
     $params = array($tmp, false);
     tag("assign_dataModel_data", $params);
     $tmp = $params[0];
     $storeInfo = array();
     foreach ($tmp as $v) {
         $storeInfo[$v["factory_code_all"]] = $v;
         $factoryCodes[] = $v["factory_code_all"];
     }
     //销售
     if (isAppLoaded("sale")) {
         $orderMap = array("OrdersDetail.factory_code_all" => array("IN", implode(",", $factoryCodes)), "Orders.dateline" => array("BETWEEN", array($dateStart, $dateEnd)), "Orders.status" => array("GT", 0), "Orders.deleted" => 0);
         $orderModel = D("OrdersDetailView");
         $tmp = $orderModel->field("factory_code_all, SUM(OrdersDetail.amount) AS total_amount, SUM(OrdersDetail.num) as total_num")->where($orderMap)->group("OrdersDetail.factory_code_all")->select();
         $ordersInfo = array();
         foreach ($tmp as $v) {
             $ordersInfo[$v["factory_code_all"]] = $v;
         }
     }
     //生产
     if (isAppLoaded("produce")) {
         $produceMap = array("ProducePlan.end_time" => array("BETWEEN", array($dateStart, $dateEnd)), "ProducePlan.status" => array("EGT", 4), "ProducePlanDetail.factory_code_all" => array("IN", implode(",", $factoryCodes)));
         $produceModel = D("ProducePlanDetailView");
         $tmp = $produceModel->field("factory_code_all, SUM(ProducePlanDetail.num) as total_num")->where($produceMap)->select();
         foreach ($tmp as $v) {
             $produceInfo[$v["factory_code_all"]] = $v["total_num"];
         }
     }
     //采购
     if (isAppLoaded("purchase")) {
         $purchaseModel = D("PurchaseDetailView");
         $purchaseMap = array("Purchase.dateline" => array("BETWEEN", array($dateStart, $dateEnd)), "Purchase.status" => array("EGT", 1), "PurchaseDetail.factory_code_all" => array("IN", implode(",", $factoryCodes)));
         $tmp = $purchaseModel->field("factory_code_all, SUM(PurchaseDetail.num) as total_num, SUM(PurchaseDetail.price) AS total_amount")->where($purchaseMap)->select();
         foreach ($tmp as $v) {
             $purchaseInfo[$v["factory_code_all"]] = $v;
         }
         foreach ($storeInfo as $k => $v) {
             $storeInfo[$k]["sale_num"] = $ordersInfo[$k]["total_num"];
             $storeInfo[$k]["sale_amount"] = $ordersInfo[$k]["total_amount"];
             $storeInfo[$k]["produce_num"] = $produceInfo[$k];
             $storeInfo[$k]["purchase_num"] = $purchaseInfo[$k]["total_num"];
             $storeInfo[$k]["purchase_amount"] = $purchaseInfo[$k]["total_amount"];
         }
     }
     $this->response(reIndex($storeInfo));
 }
Пример #7
0
 public function read()
 {
     if (!$_GET["includeRows"] or $_GET['workflow']) {
         return parent::read();
     }
     //        $this->readModel = "PurchaseView";
     //        $formData = parent::read(true);
     $formData = D("PurchaseView")->find($_GET['id']);
     $formData["inputTime"] = $formData["dateline"] * 1000;
     //        $formData["total_amount"] = $formData["total_price"];
     //        $formData["total_amount_real"] = $formData["total_price_real"];
     //        $formData["total_num"] = $formData["quantity"];
     $rowModel = D("PurchaseDetailView");
     $rows = $rowModel->where("PurchaseDetail.purchase_id=" . $formData["id"])->select();
     //        echo $rowModel->getLastSql();exit;
     $modelIds = array();
     $rowData = array();
     foreach ($rows as $v) {
         $tmp = explode(DBC("goods.unique.separator"), $v["factory_code_all"]);
         //根据factory_code_all factory_code - standard - version
         $factory_code = array_shift($tmp);
         $modelIds = array_merge($modelIds, $tmp);
         $v["modelIds"] = $tmp;
         $v["goods_id"] = sprintf("%s_%s_%s", $factory_code, $v["goods_id"], $v["goods_category_id"]);
         // factory_code, id, catid
         $v["goods_id_label"] = sprintf("%s", $v["goods_name"]);
         //             $v["amount"] = $v["price"];
         $rowData[$v["id"]] = $v;
     }
     //        array_flip(array_flip($modelIds));
     $formData["customer_id_label"] = $formData["customer"];
     $params = array($rowData, $modelIds);
     tag("assign_dataModel_data", $params);
     $formData["rows"] = reIndex($params[0]);
     /*
      * 相关单据
      * **/
     $relateItem = array();
     $id = abs(intval($_GET["id"]));
     if (isAppLoaded("store")) {
         $tmp = D("Stockin")->toRelatedItem("Purchase", $id);
         if ($tmp) {
             $relateItem = array_merge($relateItem, $tmp);
         }
     }
     if (isAppLoaded("finance")) {
         $tmp = D("FinancePayPlan")->toRelatedItem("Purchase", $id);
         if ($tmp) {
             $relateItem = array_merge($relateItem, $tmp);
         }
     }
     if ($formData["source_model"] == "ProducePlan" && $formData["source_id"] && isAppLoaded("produce")) {
         $tmp = D("ProducePlan")->getRelatedItem($formData["source_id"]);
         if ($tmp) {
             $relateItem[] = $tmp;
         }
     }
     $formData["relatedItems"] = $relateItem;
     $this->response($formData);
 }