//Service
class Product_Service_PackagingMaterials {
/*
* $combination array() 结合(字段,值)
*/
public static function add($combination) {
$Object = new Product_Model_PackagingMaterials();
return $Object->add($combination);
}
/*
* $combination array() 条件
* $type SQL 函数
* $orderBy DESC || ASC 排序
* $page Integer 页
* $pageSize Integer 条数
*/
public static function getCombination($combination, $type = '*', $orderBy = 'pm_id asc', $page = 0, $pageSize = 0) {
$Object = new Product_Model_PackagingMaterials();
return $Object->getCombination($combination, $type, $orderBy, $page, $pageSize);
}
/*
* 生成包材入库明细数据
*
* $warehouseId Integer 仓库
* $productId Integer 产品 ID
* $beginningQuantity Integer 期初数量
* $quantity Integer 当前操作数量
* $code String 入库单号
*/
public static function generateInto($warehouseId, $productId, $beginningQuantity, $quantity, $code) {
$combination = array(
'warehouse_id' => $warehouseId,
'product_id' => $productId,
//包材用户 ID
'customer_id' => 'SFCHC',
);
$productIds = Product_Service_Product::getByJoinCondition($combination, '*');
if ($productIds) {
$data = array(
'product_id' => $productId,
'product_sku' => $productIds[0]['product_sku'],
'product_title_cn' => $productIds[0]['product_title_cn'],
'pm_type' => 0,
'pm_beginning_quantity' => $beginningQuantity,
'pm_beginning_price' => 0.00,
'pm_beginning_gold' => 0.00,
'pm_quantity' => $quantity,
'pm_price' => 0.00,
'pm_gold' => 0.00,
'pm_end_semester_quantity' => $beginningQuantity + $quantity,
'pm_end_semester_price' => 0.00,
'pm_end_semester_gold' => 0.00,
'pm_code' => $code,
'warehouse_id' => $warehouseId,
'pm_create_date' => date('Y-m-d H:i:s'),
);
$combin = array(
'product_id' => $productId,
'product_sku' => $productIds[0]['product_sku'],
'warehouse_id' => $warehouseId,
);
$pmIds = self::getCombination($combin, '*', 'pm_id desc');
if ($pmIds) {
$data['pm_beginning_price'] = $pmIds[0]['pm_end_semester_price'];
$data['pm_beginning_gold'] = $pmIds[0]['pm_end_semester_gold'];
} else {
$psId = Product_Service_ProductStocket::getByProductId($productId, $warehouseId);
$data['pm_beginning_price'] = $psId['ps_stocket_unit_price'] ? $productIds[0]['product_declared_value'] : $psId['ps_stocket_unit_price'];
$data['pm_beginning_gold'] = $data['pm_beginning_quantity'] * $data['pm_beginning_price'];
}
$combinat = array(
'product_id' => $productId,
'receiving_code' => $code,
);
$riId = Product_Service_ReceivingItem::getByReceivingAsnPid($combinat);
if ($riId && $riId['unitPrice']) {
$data['pm_price'] = $riId['unitPrice'];
}
$data['pm_gold'] = $data['pm_quantity'] * $data['pm_price'];
$data['pm_end_semester_gold'] = $data['pm_beginning_gold'] + $data['pm_gold'];
if ($data['pm_end_semester_gold'] != 0 && $data['pm_end_semester_quantity'] != 0) {
$data['pm_end_semester_price'] = round($data['pm_end_semester_gold'] / $data['pm_end_semester_quantity'], 2, PHP_ROUND_HALF_DOWN);
}
self::add($data);
Product_Service_ProductStocket::update(array('ps_stocket_unit_price' => $data['pm_end_semester_price']), $productId, $warehouseId);
}
}
/*
* 生成包材出库明细数据
*
* $ordersCode String 订单号
*/
public static function generateOutbound($ordersCode) {
$Object = new Order_Model_Order();
$combination = array(
//包材用户 ID
'customer_id' => 'SFCHC',
'orders_code' => $ordersCode,
);
$ordersIds = $Object->getForOnepieceStop($combination, '*', 'op_id asc');
if ($ordersIds) {
$data = array(
'product_id' => 1,
'product_sku' => '',
'product_title_cn' => '',
'pm_type' => 1,
'pm_beginning_quantity' => 0,
'pm_beginning_price' => 0.00,
'pm_beginning_gold' => 0.00,
'pm_quantity' => 0,
'pm_price' => 0.00,
'pm_gold' => 0.00,
'pm_end_semester_quantity' => 0,
'pm_end_semester_price' => 0.00,
'pm_end_semester_gold' => 0.00,
'pm_code' => '',
'warehouse_id' => 1,
'pm_create_date' => date('Y-m-d H:i:s'),
);
foreach ($ordersIds as $value) {
$data['product_id'] = $value['product_id'];
$productIds = Product_Service_Product::getByProductId($value['product_id']);
if ($productIds) {
$data['product_sku'] = $productIds['product_sku'];
$data['product_title_cn'] = $productIds['product_title_cn'];
}
$combinat = array(
'product_id' => $value['product_id'],
'product_sku' => $productIds['product_sku'],
'warehouse_id' => $value['warehouse_id'],
);
$pmIds = self::getCombination($combinat, '*', 'pm_id desc');
if ($pmIds) {
$data['pm_beginning_quantity'] = $pmIds[0]['pm_end_semester_quantity'];
$data['pm_beginning_price'] = $pmIds[0]['pm_end_semester_price'];
$data['pm_beginning_gold'] = $pmIds[0]['pm_end_semester_gold'];
$data['pm_price'] = $pmIds[0]['pm_end_semester_price'];
$data['pm_end_semester_price'] = $pmIds[0]['pm_end_semester_price'];
} else {
$psId = Product_Service_ProductStocket::getByProductId($value['product_id'], $value['warehouse_id']);
if ($psId) {
$data['pm_beginning_quantity'] = $psId['ps_quantity'] + $psId['ps_quantity_hold'] + $psId['ps_quantity_problem'] + $psId['ps_quantity_p_hold'];
$data['pm_beginning_price'] = $psId['ps_stocket_unit_price'] ? $productIds['product_declared_value'] : $psId['ps_stocket_unit_price'];
$data['pm_price'] = $psId['ps_stocket_unit_price'];
$data['pm_end_semester_price'] = $psId['ps_stocket_unit_price'];
}
$data['pm_beginning_gold'] = $data['pm_beginning_quantity'] * $data['pm_beginning_price'];
}
$data['pm_quantity'] = $value['op_quantity'];
$data['pm_gold'] = $data['pm_quantity'] * $data['pm_price'];
$data['pm_end_semester_quantity'] = $data['pm_beginning_quantity'] - $data['pm_quantity'];
$data['pm_end_semester_gold'] = $data['pm_beginning_gold'] - $data['pm_gold'];
$data['pm_code'] = $value['orders_code'];
$data['pm_applicant'] = $value['consignee_first_name'];
$data['pm_approver'] = $value['consignee_last_name'];
$data['warehouse_id'] = $value['warehouse_id'];
self::add($data);
}
}
}
/*
* 生成包材盘点明细数据
*
* $warehouseId Integer 仓库
* $productId Integer 产品 ID
* $beginningQuantity Integer 期初数量
* $quantity Integer 当前操作数量
* $code String 盘点任务单号
* $type Integer 盘点库存加或者减
*/
public static function generateInventory($warehouseId, $productId, $beginningQuantity, $quantity, $code, $type) {
$combination = array(
'warehouse_id' => $warehouseId,
'product_id' => $productId,
//包材用户 ID
'customer_id' => 'SFCHC',
);
$productIds = Product_Service_Product::getByJoinCondition($combination, '*');
if ($productIds) {
$type == 2 ? $endSemesterQuantity = $beginningQuantity + $quantity : $endSemesterQuantity = $beginningQuantity - $quantity;
$data = array(
'product_id' => $productId,
'product_sku' => $productIds[0]['product_sku'],
'product_title_cn' => $productIds[0]['product_title_cn'],
'pm_type' => $type,
'pm_beginning_quantity' => $beginningQuantity,
'pm_beginning_price' => 0.00,
'pm_beginning_gold' => 0.00,
'pm_quantity' => $quantity,
'pm_price' => 0.00,
'pm_gold' => 0.00,
'pm_end_semester_quantity' => $endSemesterQuantity,
'pm_end_semester_price' => 0.00,
'pm_end_semester_gold' => 0.00,
'pm_code' => $code,
'warehouse_id' => $warehouseId,
'pm_create_date' => date('Y-m-d H:i:s'),
);
$combinat = array(
'product_id' => $productId,
'product_sku' => $productIds[0]['product_sku'],
'warehouse_id' => $warehouseId,
);
$pmIds = self::getCombination($combinat, '*', 'pm_id desc');
if ($pmIds) {
$data['pm_beginning_price'] = $pmIds[0]['pm_end_semester_price'];
$data['pm_beginning_gold'] = $pmIds[0]['pm_beginning_gold'];
$data['pm_price'] = $pmIds[0]['pm_end_semester_price'];
$data['pm_end_semester_price'] = $pmIds[0]['pm_end_semester_price'];
} else {
$psId = Product_Service_ProductStocket::getByProductId($productId, $warehouseId);
if ($psId) {
$data['pm_beginning_price'] = $psId['ps_stocket_unit_price'] ? $productIds[0]['product_declared_value'] : $psId['ps_stocket_unit_price'];
$data['pm_price'] = $psId['ps_stocket_unit_price'];
$data['pm_end_semester_price'] = $psId['ps_stocket_unit_price'];
}
$data['pm_beginning_gold'] = $data['pm_beginning_quantity'] * $data['pm_beginning_price'];
}
$data['pm_gold'] = $data['pm_quantity'] * $data['pm_price'];
$type == 2 ? $data['pm_end_semester_gold'] = $data['pm_beginning_gold'] + $data['pm_gold'] : $data['pm_end_semester_gold'] = $data['pm_beginning_gold'] - $data['pm_gold'];
self::add($data);
}
}
}
//Model
class Product_Model_PackagingMaterials {
private $_table;
public function __construct() {
$this->_table = new Product_Model_DbTable_PackagingMaterials();
}
/*
* $combination array() 结合(字段,值)
*/
public function add($combination) {
return $this->_table->insert($combination);
}
/*
* $combination array() 条件
* $type SQL 函数
* $orderBy DESC || ASC 排序
* $page Integer 页
* $pageSize Integer 条数
*/
public function getCombination($combination, $type = '*', $orderBy = 'pm_id asc', $page = 0, $pageSize = 0) {
$select = $this->_table->getAdapter()->select();
$table = $this->_table->info('name');
$select->from($table, $type);
$select->where('1 = ?', 1);
if (isset($combination['product_id']) && $combination['product_id'] != '') {
$select->where('product_id = ?', $combination['product_id']);
}
if (isset($combination['product_sku']) && $combination['product_sku'] != '') {
$select->where('product_sku = ?', $combination['product_sku']);
}
if (isset($combination['warehouse_id']) && $combination['warehouse_id'] != '') {
$select->where('warehouse_id = ?', $combination['warehouse_id']);
}
if (isset($combination['start_date']) && $combination['start_date'] != '') {
$select->where('pm_create_date >= ?', $combination['start_date']);
}
if (isset($combination['end_date']) && $combination['end_date'] != '') {
$select->where('pm_create_date <= ?', $combination['end_date']);
}
if (isset($combination['pm_type']) && $combination['pm_type'] !== '') {
$select->where('pm_type = ?', $combination['pm_type']);
}
if ($type == 'count(*)') {
return $this->_table->getAdapter()->fetchOne($select);
} else {
$select->order($orderBy);
if ($pageSize > 0 and $page > 0) {
$start = ($page - 1) * $pageSize;
$select->limit($pageSize, $start);
}
return $this->_table->getAdapter()->fetchAll($select->__toString());
}
}
}
//Model_DbTable
class Product_Model_DbTable_PackagingMaterials extends Zend_Db_Table_Abstract {
//数据表名称
protected $_name = 'packaging_materials';
//主键
protected $_primary = 'pm_id';
protected $_sequence = true;
}
生成包材入、出、盘点库存数据
最新推荐文章于 2021-05-26 10:55:32 发布