Beispiel #1
0
 public function getPrice($code, $supplier_id, $fix = true, $date = null, $qty = null, $currency = null)
 {
     $price = array('price' => 0, 'currency' => '');
     $res = $this->fetchAll("code = '" . $code . "' and supplier_id = " . $supplier_id);
     if ($res->count() > 0) {
         $data = $res->toArray();
         if ($date && !$fix) {
             $ladder = new Erp_Model_Warehouse_Ladder();
             $price_ladder = $ladder->getPrice($data[0]['id'], $date, $qty);
             if ($price_ladder['price'] > 0) {
                 $price = $price_ladder;
             } else {
                 $price['price'] = $data[0]['price'];
                 $price['currency'] = $data[0]['currency'];
             }
         } else {
             $price['price'] = $data[0]['price'];
             $price['currency'] = $data[0]['currency'];
         }
     }
     if ($currency != $price['currency']) {
         $rate = new Erp_Model_Setting_Currencyrate();
         $rate1 = $rate->getRateByCode($currency, $date);
         $rate2 = $rate->getRateByCode($price['currency'], $date);
         $price['price'] = round($price['price'] * ($rate2 / $rate1), 8);
     }
     /* echo '<pre>';
        print_r($price);
        exit; */
     return $price;
 }
Beispiel #2
0
 public function getPrice($code, $customer_id, $fix = true, $date = null, $qty = null, $currency = null)
 {
     $price = array('price_tax' => 0, 'price' => 0, 'currency' => 'CNY');
     $sql = $this->select()->setIntegrityCheck(false)->from(array('t1' => $this->_name), array('id', 'price_final', 'currency'))->joinLeft(array('t2' => $this->_dbprefix . 'erp_sale_price'), "t1.price_id = t2.id", array('price_tax'))->where("t1.active = 1 and t1.code = '" . $code . "' and t1.active_date <= '" . $date . "' and t1.customer_id = " . $customer_id);
     $data = $this->fetchAll($sql);
     $taxRateModel = new Erp_Model_Setting_Taxrate();
     if (count($data)) {
         $price['price_tax'] = $data[0]['price_tax'];
         if ($date && !$fix) {
             $ladder = new Erp_Model_Sale_Priceitemladder();
             $price_ladder = $ladder->getPrice($data[0]['id'], $qty);
             if ($price_ladder > 0) {
                 $price['price'] = $price_ladder;
                 $price['currency'] = $data[0]['currency'];
             } else {
                 $price['price'] = $data[0]['price_final'];
                 $price['currency'] = $data[0]['currency'];
             }
         } else {
             $price['price'] = $data[0]['price_final'];
             $price['currency'] = $data[0]['currency'];
         }
     }
     if ($currency != $price['currency']) {
         $rate = new Erp_Model_Setting_Currencyrate();
         $rate1 = $rate->getRateByCode($currency, $date);
         $rate2 = $rate->getRateByCode($price['currency'], $date);
         $price['price'] = round($price['price'] * ($rate2 / $rate1), 8);
     }
     /* echo '<pre>';
        print_r($price);
        exit; */
     return $price;
 }
Beispiel #3
0
 public function saveItemDetails($splitData)
 {
     if ($splitData['items_order_item_id']) {
         $items = new Erp_Model_Purchse_Receiveitems();
         $itemsorder = new Erp_Model_Purchse_Receiveitemsorder();
         $rate = new Erp_Model_Setting_Currencyrate();
         $stock = new Erp_Model_Stock_Stock();
         // 更新是先清空之前所保存的收货数据分拆信息
         $itemsorder->delete("receive_item_id = " . $splitData['receive_item_id']);
         $now = date('Y-m-d H:i:s');
         $user_session = new Zend_Session_Namespace('user');
         $user_id = $user_session->user_info['user_id'];
         // 转换币种价格,按本币价格入库
         $price = round($splitData['items_price'] * $rate->getRateByCode($splitData['items_order_currency'], $splitData['items_order_date']), 2);
         $total = round($price * $splitData['items_qty'], 2);
         $data = array('receive_item_id' => $splitData['receive_item_id'], 'order_item_id' => $splitData['items_order_item_id'], 'qty' => $splitData['items_qty'], 'price' => $price, 'total' => $total, 'order_id' => $splitData['items_order_id'], 'order_number' => $splitData['items_order_number'], 'code' => $splitData['items_code'], 'create_user' => $user_id, 'create_time' => $now);
         $itemsorder->insert($data);
         // 更新行总计
         $items->update(array('total' => $total), "id = " . $splitData['receive_item_id']);
         // 记录库存数据
         $stockData = array('code' => $splitData['items_code'], 'warehouse_code' => $splitData['items_warehouse_code'], 'qty' => $splitData['items_qty'], 'total' => $total, 'create_user' => $user_id, 'create_time' => $now, 'doc_type' => '采购收货', 'doc_number' => $splitData['receive_number']);
         $stock->insert($stockData);
     }
 }
Beispiel #4
0
 public function exportcsvAction()
 {
     set_time_limit(0);
     $fa = new Product_Model_Fa();
     $bomPrice = new Product_Model_BomPrice();
     $son = new Product_Model_Son();
     $catalog = new Product_Model_Catalog();
     $materiel = new Product_Model_Materiel();
     $request = $this->getRequest()->getParams();
     $faName = $fa->getName();
     $priceName = $bomPrice->getName();
     $mName = $materiel->getName();
     $catalogName = $catalog->getName();
     $db = $fa->getAdapter();
     $whereSearch = "{$faName}.state != 'Obsolete'";
     foreach ($request as $k => $v) {
         if ($v) {
             if ($k == 'search_key') {
                 $whereSearch .= " and (ifnull({$faName}.remark,'') like '%{$v}%' or ifnull({$mName}.name,'') like '%{$v}%' or ifnull({$mName}.description,'') like '%{$v}%' or ifnull({$catalogName}.model_internal, '') like '%{$v}%')";
             } else {
                 if ("search_fa" == $k && $v) {
                     $whereSearch .= " and {$faName}.code like '%{$v}%'";
                 } else {
                     if ("search_archive_date_from" == $k && $v) {
                         $whereSearch .= " and {$faName}.bom_upd_time >= '" . str_replace('T', ' ', $v) . "'";
                     } else {
                         if ("search_archive_date_to" == $k && $v) {
                             $whereSearch .= " and v.bom_upd_time <= '" . str_replace('T00:00:00', ' 23:59:59', $v) . "'";
                         } else {
                             if ("search_son" == $k && $v) {
                                 $recordkey = "";
                                 $sonData = $db->query("select group_concat(recordkey) as recordkey from oa_product_bom_son where code like '%{$v}%'")->fetchObject();
                                 if ($sonData && $sonData->recordkey) {
                                     $recordkey = $sonData->recordkey;
                                 }
                                 if (!$recordkey) {
                                     $recordkey = "0";
                                 }
                                 $whereSearch .= " and {$faName}.recordkey in ({$recordkey})";
                             } else {
                                 if ("search_recordkey" == $k && $v) {
                                     $whereSearch .= " and {$faName}.recordkey = '{$v}'";
                                 } else {
                                     if ("explanded" == $k && $v) {
                                         $explanded = json_decode($v);
                                     } else {
                                         $col = str_replace('search_', '', $k);
                                         if ($col != $k) {
                                             // 查询条件
                                             $whereSearch .= " and ifnull({$faName}." . $col . ",'') like '%" . $v . "%'";
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $rate = new Erp_Model_Setting_Currencyrate();
     $date = date('Y-m-d');
     $rateCny = $rate->getRateByCode('CNY', $date);
     $rateUsd = $rate->getRateByCode('USD', $date);
     $user_session = new Zend_Session_Namespace('user');
     $user = $user_session->user_info['employee_id'];
     $sort = $this->getRequest()->getParam('sort');
     if ($sort) {
         $sort = json_decode($sort);
         $sort = $sort[0];
         $property = $sort->property;
         $direction = $sort->direction;
         if (in_array($property, array('code', 'ver', 'state', 'remark'))) {
             $order = array($faName . '.' . $property . ' ' . $direction);
         } else {
             if (in_array($property, array('low_cny', 'low_usd', 'high_cny', 'high_usd', 'average_cny', 'average_usd', 'update_time'))) {
                 $order = array($bomPrice->getName() . '.' . $property . ' ' . $direction);
             } else {
                 if (in_array($property, array('description', 'name'))) {
                     $order = array($mName . '.' . $property . ' ' . $direction);
                 }
             }
         }
     }
     if (isset($order)) {
         $order[] = $faName . '.code';
     } else {
         $order = array($faName . '.code');
     }
     // 获取物料数据
     $cjoin = array(array('type' => LEFTJONIN, 'table' => $catalog->getName(), 'condition' => $catalog->getName() . '.id = ' . $fa->getName() . '.project_no'), array('type' => INNERJOIN, 'table' => $bomPrice->getName(), 'condition' => $bomPrice->getName() . '.recordkey = ' . $fa->getName() . '.recordkey'), array('type' => INNERJOIN, 'table' => $materiel->getName(), 'condition' => $materiel->getName() . '.id = ' . $fa->getName() . '.id'));
     $join = array(array('type' => LEFTJONIN, 'table' => $catalog->getName(), 'condition' => $catalog->getName() . '.id = ' . $fa->getName() . '.project_no', 'cols' => array('project_no_name' => 'model_internal')), array('type' => INNERJOIN, 'table' => $bomPrice->getName(), 'condition' => $bomPrice->getName() . '.recordkey = ' . $fa->getName() . '.recordkey', 'cols' => array("low_cny", "low_usd", 'high_cny', 'high_usd', 'average_cny', 'average_usd', 'update_time')), array('type' => INNERJOIN, 'table' => $materiel->getName(), 'condition' => $materiel->getName() . '.id = ' . $fa->getName() . '.id', 'cols' => array("name", "description")));
     $data = $fa->getJoinList($whereSearch, $join, null, $order);
     $allData = array();
     for ($i = 0; $i < count($data); $i++) {
         // 对于每个BOM,递归计算每个下级物料或BOM的价格
         if (!$data[$i]['low_cny']) {
             $price = $bomPrice->calcBomPrice($data[$i]['recordkey'], 'CNY');
             $data[$i]['low_cny'] = $price['low'];
             $data[$i]['high_cny'] = $price['high'];
             $data[$i]['average_cny'] = $price['average'];
             $data[$i]['low_usd'] = round($data[$i]['low_cny'] * ($rateCny / $rateUsd), 4);
             $data[$i]['high_usd'] = round($data[$i]['high_cny'] * ($rateCny / $rateUsd), 4);
             $data[$i]['average_usd'] = round($data[$i]['average_cny'] * ($rateCny / $rateUsd), 4);
         }
         $allData[] = $data[$i];
     }
     print chr(0xef) . chr(0xbb) . chr(0xbf);
     // 获取物料数据
     $data_csv = array();
     $title = array('cnt' => '#', 'code' => 'BOM号', 'ver' => '版本', 'state' => '状态', 'low_cny' => '最低价格-人民币', 'high_cny' => '最高价格-人民币', 'average_cny' => '平均价格-人民币', 'low_usd' => '最低价格-美元', 'high_usd' => '最高价格-美元', 'average_usd' => '平均价格-美元', 'update_time' => '更新时间', 'name' => '物料名称', 'description' => '物料描述', 'project_no_name' => '产品型号', 'bom_upd_time' => '归档时间', 'remark' => '备注');
     $title = $this->object_array($title);
     $date = date('YmdHsi');
     $filename = 'bomprice-' . $date;
     $path = "../temp/" . $filename . ".csv";
     $file = fopen($path, "w");
     fputcsv($file, $title);
     array_push($data_csv, $title);
     $typeids = array();
     $typenames = array();
     $k = 0;
     for ($i = 0; $i < count($data); $i++) {
         $d = $data[$i];
         $k++;
         $info = array('cnt' => $k, 'code' => Helper::ifNull($d, 'code'), 'ver' => "V" . $d['ver'], 'state' => Helper::ifNull($d, 'state'), 'low_cny' => Helper::ifNull($d, 'low_cny'), 'high_cny' => Helper::ifNull($d, 'high_cny'), 'average_cny' => Helper::ifNull($d, 'average_cny'), 'low_usd' => Helper::ifNull($d, 'low_usd'), 'high_usd' => Helper::ifNull($d, 'high_usd'), 'average_usd' => Helper::ifNull($d, 'average_usd'), 'update_time' => $d['update_time'], 'name' => Helper::ifNull($d, 'name'), 'description' => Helper::ifNull($d, 'description'), 'project_no_name' => Helper::ifNull($d, 'project_no_name'), 'bom_upd_time' => $d['bom_upd_time'], 'remark' => Helper::ifNull($d, 'remark'));
         $bomd = $this->object_array($info);
         fputcsv($file, $bomd);
     }
     fclose($file);
     $this->operate("BOM导出");
     echo $filename;
     exit;
 }
 public function exportcsvAction()
 {
     set_time_limit(0);
     $request = $this->getRequest()->getParams();
     $fa = new Product_Model_Fa();
     $son = new Product_Model_Son();
     $db = $fa->getAdapter();
     $explanded = array();
     $whereSearch = "1=1";
     foreach ($request as $k => $v) {
         if ($v) {
             if ("search_recordkey" == $k && $v) {
                 $whereSearch .= " and t1.recordkey = '{$v}'";
             } else {
                 if ("explanded" == $k && $v) {
                     $explanded = json_decode($v);
                 } else {
                     $col = str_replace('search_', '', $k);
                     if ($col != $k) {
                         // 查询条件
                         $whereSearch .= " and ifnull(t1." . $col . ",'') like '%" . $v . "%'";
                     }
                 }
             }
         }
     }
     // 获取物料数据
     $data = $fa->getList($whereSearch, null, null);
     print chr(0xef) . chr(0xbb) . chr(0xbf);
     // 获取物料数据
     $data_csv = array();
     $title = array('cnt' => '#', 'code' => '物料号', 'state' => '状态', 'name' => '物料名称', 'description' => '物料描述', 'low_cny' => '最低价格-人民币', 'high_cny' => '最高价格-人民币', 'average_cny' => '平均价格-人民币', 'low_usd' => '最低价格-美元', 'high_usd' => '最高价格-美元', 'average_usd' => '平均价格-美元', 'project_no_name' => '产品型号', 'qty' => '数量', 'replace' => '替代料', 'partposition' => '器件位置', 'remark' => '备注');
     $date = date('YmdHsi');
     // 文件名
     if (count($data) == 1) {
         $name = $data[0]['code'];
     } else {
         $zip = new ZipArchive();
         $zipFileName = "boms" . $date . ".zip";
         $zipFile = "../temp/{$zipFileName}";
         $zipPath = "../temp/boms" . $date . "/";
         if (!file_exists($zipPath)) {
             mkdir($zipPath);
         }
         $name = "bom_list";
     }
     $bomPrice = new Product_Model_BomPrice();
     $currencyrate = new Erp_Model_Setting_Currencyrate();
     $date = date('Y-m-d');
     $rateCny = $currencyrate->getRateByCode('CNY', $date);
     $rateUsd = $currencyrate->getRateByCode('USD', $date);
     $rate = round($rateCny / $rateUsd, 4);
     $title = $this->object_array($title);
     $typeids = array();
     $typenames = array();
     $k = 0;
     for ($i = 0; $i < count($data); $i++) {
         $push_data = array();
         $d = $data[$i];
         $k++;
         $price = $bomPrice->calcBomPrice($d['recordkey'], 'CNY');
         $info = array('cnt' => $k, 'code' => Helper::ifNull($d, 'code') . " V" . $d['ver'], 'state' => Helper::ifNull($d, 'state'), 'name' => Helper::ifNull($d, 'name'), 'description' => Helper::ifNull($d, 'description'), 'low_cny' => $price['low'], 'low_usd' => round($price['low'] * $rate, 4), 'high_cny' => $price['high'], 'high_usd' => round($price['high'] * $rate, 4), 'average_cny' => $price['average'], 'average_usd' => round($price['average'] * $rate, 4), 'qty' => $d['qty'], 'replace' => Helper::ifNull($d, 'replace'), 'partposition' => Helper::ifNull($d, 'partposition'), 'remark' => Helper::ifNull($d, 'remark'));
         $filename = $info['code'] . '-' . $date;
         if (isset($zipPath)) {
             $path = $zipPath . $filename . ".csv";
         } else {
             $path = "../temp/" . $filename . ".csv";
         }
         $file = fopen($path, "w");
         fputcsv($file, $title);
         array_push($data_csv, $title);
         $info['count'] = 0;
         $push_data[] = $info;
         $push_data = $this->getBomInfo($push_data, $fa, $son, $d['recordkey'], 1, $explanded, $rate);
         foreach ($push_data as $bomdata) {
             $count = $bomdata['count'];
             $bomdata['count'] = "";
             $prefix = "";
             for ($ii = 0; $ii < $count; $ii++) {
                 $prefix .= "  ";
             }
             $bomdata['code'] = $prefix . $bomdata['code'];
             $bomd = $this->object_array($bomdata);
             fputcsv($file, $bomd);
         }
         fclose($file);
     }
     /* foreach($push_data as $data) {
             	$count = $data['count'];
             	$data['count'] = "";
             	$prefix = "";
             	for($i = 0;$i < $count; $i++){
             		$prefix .= "  ";
             	}
             	$data['code'] = $prefix.$data['code'];
             	$d = $this->object_array($data);
                 fputcsv($file, $d);
             }
     
             fclose($file); */
     $this->operate("BOM导出");
     if (isset($zipPath)) {
         $zip = new ZipArchive();
         $helper = new Application_Model_Helpers();
         if ($zip->open($zipFile, ZipArchive::OVERWRITE) === TRUE) {
             $datalist = $this->list_dir($zipPath);
             foreach ($datalist as $val) {
                 if (file_exists($val)) {
                     $zip->addFile($val, basename($val));
                     //第二个参数是放在压缩包中的文件名称,如果文件可能会有重复,就需要注意一下
                 }
             }
             $zip->close();
             //关闭
         }
         echo $zipFileName;
     } else {
         echo $filename;
     }
     exit;
 }