public function run() { $purchase = D("Purchase"); $thePurchase = $purchase->find($this->mainrowId); $purchaseDetail = D("PurchaseDetail"); $thePurchaseDetail = $purchaseDetail->where("purchase_id=" . $thePurchase["id"])->select(); // $purchase->startTrans(); $data = array("subject" => "采购入库", "dateline" => CTS, "total_num" => $thePurchase["total_num"], "status" => 0, "user_id" => getCurrentUid(), "source_model" => "Purchase", "source_id" => $this->mainrowId, "stock_manager" => 0, "memo" => $thePurchase["memo"]); $stockin = D("Stockin"); foreach ($thePurchaseDetail as $trd) { $items[] = array("goods_id" => $trd["goods_id"], "num" => $trd["num"], "factory_code_all" => $trd["factory_code_all"], "stock_id" => 0, "memo" => $trd["memo"]); } if (!$stockin->newBill($data, $items)) { $this->response(array("error" => 1, "msg" => $stockin->getError())); } // $stockin->commit(); // // //新建入库流程 // import("@.Workflow.Workflow"); // $workflow = new Workflow("stockin"); // $rs = $workflow->doNext($lastId, "", true, true); //新建 // $rs = $workflow->doNext($lastId, "", true, true); //保存 // $rs = $workflow->doNext($lastId, "", true, true); //提交确认 // var_dump($rs);exit; // exit; }
public function update($post) { $old = $this->get(0, false); $btns = array(); $blocks = array(); foreach ($post["blocks"] as $k => $v) { $blocksNames[] = $v["name"]; $postBlocks[$v["name"]] = $v; } $blockConfigureKey = array("col", "row", "width", "height", "config"); foreach ($postBlocks as $name => $block) { if (!I("post.customize") && !$block["selected"]) { continue; } foreach ($blockConfigureKey as $key) { $block[$key] = isset($block[$key]) && !is_null($block[$key]) ? $block[$key] : $old["blocks"][$name][$key]; } $blocks[$name] = $block; } foreach ($post["btns"] as $btn) { if (!$btn["selected"]) { continue; } $btns[] = array("name" => $btn["name"], "listorder" => $btn["listorder"]); } $old["btns"] = $btns; $old["blocks"] = $blocks; $this->add(array("uid" => getCurrentUid(), "data" => json_encode($old)), null, true); }
public function run() { $returns = D("Returns"); $theReturns = $returns->find($this->mainrowId); $returnDetail = D("ReturnsDetail"); $theReturnsDetail = $returnDetail->where("returns_id=" . $theReturns["id"])->select(); $data = array("subject" => "退货入库", "dateline" => CTS, "total_num" => $theReturns["total_num"], "status" => 1, "user_id" => getCurrentUid(), "source_model" => "Returns", "source_id" => $this->mainrowId, "stock_manager" => 0, "memo" => $theReturns["memo"]); $stockin = D("Stockin"); // $stockinDetail = D("StockinDetail"); // // $stockin->startTrans(); // // $lastId = $stockin->add($data); // echo $lastId;exit; // var_dump($thePurchaseDetail);exit; foreach ($theReturnsDetail as $trd) { $items[] = array("goods_id" => $trd["goods_id"], "num" => $trd["num"], "factory_code_all" => $trd["factory_code_all"], "stock_id" => 0, "memo" => $trd["memo"]); // print_r($data);exit; // if(!$stockinDetail->add($data)) { // $stockin->rollback(); // return false; // } } if (!$stockin->newBill($data, $items)) { $this->response(array("error" => 1)); } // exit; }
public function formatData($postData) { if (!$postData["id"]) { $data["bill_id"] = makeBillCode("CK"); $data["source_id"] = $postData["source_id"] ? $postData["source_id"] : ""; $data["source_model"] = $postData["source_model"] ? $postData["source_model"] : ""; $data["stock_manager"] = getCurrentUid(); $data["status"] = 0; } else { $data["id"] = $postData["id"]; } if ($postData["dateline"]) { if (strtotime($postData['dateline'])) { $data["dateline"] = strtotime($postData['dateline']); } else { $data["dateline"] = strtotime($postData['dateline']); } } else { $data["dateline"] = CTS; } $data["total_num"] = $postData["total_num"]; $data["memo"] = $postData["memo"]; $rows = array(); $needed = array("goods_id", "num"); foreach ($postData["rows"] as $row) { list($fc, $goods_id) = explode("_", $row["goods_id"]); if (!checkParamsFull($row, $needed) || !$row["num"]) { continue; } $rows[] = array("id" => $row["id"] ? $row["id"] : 0, "stockout_id" => $row["stockout_id"], "factory_code_all" => makeFactoryCode($row, $fc), "goods_id" => $goods_id, "goods_id_label" => $row["goods_id_label"], "stock_id" => $row["stock"], "num" => $row["num"], "store_num" => $row["store_num"], "outed" => $row["outed"] ? $row["outed"] : 0, "memo" => $row["memo"]); } $data["rows"] = $rows; return $data; }
public function read() { unset($_SESSION["user"]["password"]); $auth = new Auth(); $rules = $auth->getAuthList(getCurrentUid()); // print_r($rules);exit; $data = array("authed" => reIndex($rules), "navs" => $this->makeNav()); $this->response($data); }
public function run(&$params) { $model = D("OperationLog"); if (!$params["uid"]) { $params["uid"] = getCurrentUid(); } $params["dateline"] = CTS; $model->add($params); }
public function record($options) { $needed = array("type", "source_id", "factory_code_all", "repository_id", "num"); foreach ($needed as $need) { if (!array_key_exists($need, $options)) { return false; } } $options["user_id"] = $options["user_id"] ? $options["user_id"] : getCurrentUid(); $options["dateline"] = $options["dateline"] ? $options["dateline"] : CTS; if (false === $this->switchModel("")->add($options)) { Log::write($this->getLastSql(), Log::SQL); } }
public function record($data) { $data["create_dateline"] = CTS; $data["status"] = 0; $data["user_id"] = getCurrentUid(); $lastId = $this->add($data); if (!$lastId) { Log::write($this->getLastSql(), Log::SQL); return false; } $workflow = new Workflow("financePay"); $workflow->doNext($lastId, "", true); return $lastId; }
/** * 1、修改库存数量 判断库存数量 * 2、修改出库单状态 */ public function run() { return false; //已切换至出库工作流 if (!IS_POST) { $map = array("source_id" => $this->mainrowId, "source_model" => "Orders"); $p = D("Stockout")->where($map)->find(); $viewModel = D("StockoutOrdersRelation"); $thePaper = $viewModel->relation(true)->find($id); $paperDetail = D("Stockout" . $thePaper["source_model"] . "DetailView"); $thePaperDetail = $paperDetail->where("StockoutDetail.stockout_id=" . $thePaper["id"])->select(); $this->view->assign("lang_title", "confirm_stockout"); $this->view->assign("list", $thePaperDetail); $this->view->assign("thePaper", $thePaper); $this->view->display("../Common/Workflow/Order/confirmStockout"); return "wait"; } $ordersDetail = D("OrdersDetailView"); $details = $ordersDetail->where("order_id=" . $this->mainrowId)->select(); // echo $ordersDetail->getLastSql();exit; if (!$details) { echo "nothings"; exit; //@todo 单据中无数据 } $stockout = D("Stockout"); $theStockout = $stockout->where("source_id=" . $this->mainrowId)->find(); $stockout->where("id=" . $theStockout["id"])->save(array("status" => 1, "outtime" => CTS, "stock_manager" => getCurrentUid())); //@todo // echo $stockout->getLastSql();exit; $stockout->startTrans(); $storeProduct = D("StockProductList"); $success = true; foreach ($details as $k => $v) { if ($v["store_num"] < $v["num"]) { $success = false; Log::write("SQL Error:" . $this->getLastSql(), Log::SQL); $stockout->rollback(); //@todo 库存不足 echo "not_full"; exit; break; } $storeProduct->where("id=" . $v["stock_product_id"])->setDec("num", $v["num"]); } if ($success) { $stockout->commit(); } // exit; }
public function run() { $this->updateStatus("Returns", $this->mainrowId, 2); //财务 if (isModuleEnabled("Finance")) { $returns = D("Returns"); $theReturns = $returns->find($this->mainrowId); $financeModel = D("FinancePayPlan"); $data = array("source_model" => "Returns", "source_id" => $this->mainrowId, "subject" => $theReturns["subject"], "supplier_id" => $theReturns["customer_id"], "amount" => $theReturns["total_price_real"], "create_dateline" => CTS, "status" => 0, "type_id" => getTypeIdByAlias("pay", "returns"), "user_id" => getCurrentUid()); $lastId = $financeModel->add($data); // echo $lastId;exit; // echo $financeModel->getLastSql();exit; import("@.Workflow.Workflow"); $workflow = new Workflow("financePay"); $node = $workflow->doNext($lastId, "", true); // var_dump($node); } }
protected function pretreatment() { if (!$_POST["pinyin"]) { $_POST["pinyin"] = Pinyin($_POST["name"]); } if (!$_GET["id"]) { $_POST["user_id"] = getCurrentUid(); $_POST["dateline"] = CTS; } $tmp["rows"] = array(); foreach ($_POST["rows"] as $k => $row) { if (count($row)) { $tmp["rows"][] = $row; } else { unset($_POST["rows"][$k]); } } $_POST["rows"] = $tmp["rows"]; }
public function addRecord($data) { $this->startTrans(); $data["status"] = 1; $data["dateline"] = CTS; $data["user_id"] = getCurrentUid(); $lastId = $this->add($data); if ($lastId) { $rs = $this->changeBalance($data["account_id"], $data["amount"], $data["type"]); } if (!$lastId or !$rs) { Log::write("SQL Error:" . $this->getLastSql(), Log::SQL); $this->rollback(); return false; } $this->where("id=" . $lastId)->save(array("status" => 1, "financer_id" => getCurrentUid())); $this->commit(); return $lastId; }
public function getLeadedDepartments($onlyId = true, $uid = null) { $uid = $uid || getCurrentUid(); $model = D("Department"); $theUser = $this->find($uid); //获取用户所在部门的所有子集部门(包含当前部门) $tmp = $model->getTree($theUser["department_id"]); $leaded = array(); foreach ($tmp as $dep) { if (inExplodeArray($uid, $dep["leader"])) { $leaded[] = $dep["id"]; } } $departments = array(); //遍历查询效率问题 foreach ($leaded as $lead) { $departments = array_merge($departments, (array) $model->getTree($lead)); } if (!$onlyId) { return $departments; } return getArrayField($departments); }
public function formatData($data) { foreach ($data["rows"] as $k => $row) { if (!$row or !$row["goods_id"]) { unset($data["rows"][$k]); continue; } list($fcCode, $goods_id, $catid) = explode("_", $row["goods_id"]); $data["rows"][$k]["goods_id"] = $goods_id; //$data["rows"][$k]["price"] = $row["amount"] ? $row["amount"] : $row["price"]; $data["rows"][$k]["factory_code_all"] = makeFactoryCode($row, $fcCode); } // $data["total_price_real"] = $data["total_amount_real"]; // $data["total_price"] = $data["total_amount"]; // $data["quantity"] = $data["total_num"]; $data["purchase_type"] = $data["purchase_type"] ? $data["purchase_type"] : 0; $data["supplier_id"] = $data["supplier_id"] ? $data["supplier_id"] : 0; if (!$data["bill_id"]) { $data["bill_id"] = makeBillCode("CG"); } $data["dateline"] = $data["inputTime"] ? strtotime($data["inputTime"]) : CTS; $data["user_id"] = getCurrentUid(); return $data; }
/** * 格式化POST或者PUT的数据 * @params $postData 提交的数据 * @params $forceInsert 强制定义为插入,而非修改(billItem是否包含ID) */ public function formatData($postData, $forceInsert = false) { $stockinModel = $this; $billData = array("bill_id" => makeBillCode(C("BILL_PREFIX.Stockin")), "subject" => $postData["subject"], "dateline" => $postData["dateline"] ? strtotime($postData["dateline"]) : CTS, "status" => 0, "user_id" => getCurrentUid(), "stock_manager" => 0, "total_num" => 0, "memo" => $postData["memo"], "type_id" => $postData["type_id"]); if ($postData["source_model"]) { $billData["source_model"] = $postData["source_model"]; $billData["source_id"] = $postData["source_id"]; } $id = abs(intval($_GET["id"])); if ($id) { $billData["id"] = $id; } $data = $postData["rows"]; $billItems = array(); $needed = array("goods_id", "num"); foreach ($data as $k => $billItem) { if (!$billItem || !$billItem["num"] || !checkParamsFull($billItem, $needed)) { continue; } list($factory_code, $goodsId, $catid) = explode("_", $billItem["goods_id"]); $billItems[$k] = array("goods_id" => $goodsId, "num" => $billItem["num"], "factory_code_all" => makeFactoryCode($billItem, $factory_code), "memo" => $billItem["memo"], "stock_id" => $billItem["stock"]); $billData["total_num"] += $billItem["num"]; if (!$forceInsert and $billItem["id"]) { $billItems[$k]["id"] = $billItem["id"]; } } return array($billData, reIndex($billItems)); }
public function _filter(&$map) { $map["uid"] = getCurrentUid(); }
public final function checkCondition($condStr) { if (!$condStr) { return true; } $condition = explode("|", $condStr); foreach ($condition as $tmp) { list($type, $cond) = explode(":", $tmp); switch ($type) { //method case "m": if (method_exists($this, $cond)) { return $this->{$cond}(); } break; //function //function case "f": if (function_exists($cond)) { return $cond($this->mainrowId); } break; //uid //uid case "u": $uid = getCurrentUid(); if (is_array($cond)) { return in_array($uid, $cond); } else { return $uid == $cond; } break; } } }
public function formatData($data) { $rowsFields = array("goods_id", "factory_code_all", "num", "unit_price", "amount", "discount", "order_id", "memo"); $data["tax_amount"] = $data["tax_amount"]; $data["total_num"] = 0; foreach ($data["rows"] as $k => $row) { if (!$row or !$row["goods_id"]) { unset($data["rows"][$k]); continue; } list($fcCode, $goods_id, $catid) = explode("_", $row["goods_id"]); $data["rows"][$k]["goods_id"] = $goods_id; $data["rows"][$k]["factory_code_all"] = makeFactoryCode($row, $fcCode); $data["total_num"] += $row["num"]; } foreach ($data["rows"] as $k => $row) { foreach ($row as $i => $j) { if (!in_array($i, $rowsFields)) { unset($data["rows"][$k][$i]); } } } $id = abs(intval($_GET["id"])); if ($id) { $data["id"] = $id; } else { $data["bill_id"] = makeBillCode("XS"); } if ($data["inputTime"] && !$id) { $data["dateline"] = strtotime($data["inputTime"]); } else { unset($data["dateline"]); } $data["saler_id"] = getCurrentUid(); $data["tax_amount"] = $data["tax_amount"] ? $data["tax_amount"] : 0; unset($data["customerInfo"]); unset($data["discount"]); unset($data["inputTime"]); return $data; }
public function checkStockManger($condition) { return true; $stockIn = D("Stockin")->find($this->mainrowId); $managers = D("Stock")->where("id=" . $stockIn["stock_id"])->getField("managers"); return inExplodeArray(getCurrentUid(), $managers); }
public function update() { $map = array("id" => abs(intval($_GET["id"])), "user_id" => getCurrentUid()); D("Remind")->where($map)->save(array("num" => 0)); }
/** * 1、修改库存数量 判断库存数量 * 2、修改出库单状态 * 3、判断是否已完全出库 * * 在显示确认出库页面时获取的数据已经减去了已出库的数量 * 所以仅需按照提交的表单进行处理即可。 * * 三种情况:足额出库 * 超额出库 * 未完全出库 */ public function run() { //判定是否已完全出库 $stockout = D("Stockout"); $theStockout = $stockout->find($this->mainrowId); if (!$_REQUEST["donext"]) { if ($theStockout["outed_num"] >= $theStockout["total_num"]) { $data = array("type" => "message", "error" => "true", "msg" => "all_have_outed_stock"); } else { $data = array("type" => "redirect", "location" => sprintf("/doWorkflow/Stockout/confirm/%d/%d", $this->currentNode["id"], $this->mainrowId)); } $this->response($data); } $data = $_POST["data"]; $dm = D("StockoutDetail"); $stockout->startTrans(); $totalOuted = 0; $storeProduct = D("StockProductList"); $dataModel = D("DataModel")->getByAlias("product"); $tmp = D("DataModelFields")->where("model_id=" . $dataModel["id"])->select(); $dataModelFields = array(); foreach ($tmp as $field) { $dataModelFields[] = $field["field_name"]; } $stockLog = D("StockLog"); $logs = array(); foreach ($data["rows"] as $k => $v) { if (!$v or !$v["id"]) { continue; } //未选择出库仓库 if (!$v["stock"]) { $stockout->rollback(); $this->error("select_stock"); return "error"; } if (strpos($v["goods_id"], "_") !== false) { list($fc, $v["goods_id"], $catid) = explode("_", $v["goods_id"]); } //本次出库总数量 $totalOuted += $v["num"]; //更新本行出库数量 $dm->where("id=" . $v["id"])->setInc("outed", $v["num"]); //出库日志(工作流MEMO) //dataModel $modelData = ""; foreach ($dataModelFields as $f) { $modelData .= "/" . $v[$f . "_label"]; } $tmp = sprintf("%s%s: %s (%s)", $v["goods_name"], $modelData, $v["num"], $v["stock_label"]); array_push($logs, $tmp); //减少库存 $storeProduct->where(array("factory_code_all" => $v["factory_code_all"], "stock_id" => $v["stock"]))->setDec("num", $v["num"]); //记录库存操作日志 $stockLog->record(array("factory_code_all" => $v["factory_code_all"], "repository_id" => $v["stock"], "num" => $v["num"], "source_id" => $this->mainrowId, "source_row_id" => $v["id"], "dateline" => CTS, "type" => 2, "memo" => $v["memo"], "goods_id" => $v["goods_id"])); } //不允许负数库存存在, 库存自动清零 //@todo 判断库存数量 if (!DBC("allow_negative_store")) { $storeProduct->where("num<0")->save(array("num" => 0)); } //更新出库单信息 $theStockout = $stockout->find($this->mainrowId); if ($theStockout["status"] == 1) { $stockout->where("id=" . $this->mainrowId)->setInc("outed_num", $totalOuted); } else { //第一次出库 $stockout->where("id=" . $this->mainrowId)->save(array("memo" => $data["memo"], "status" => 1, "outtime" => CTS, "outed_num" => $totalOuted, "stock_manager" => getCurrentUid())); } //本次出库日志 $this->context['memo'] = implode("\n", $logs); $stockout->commit(); }