Exemplo n.º 1
0
/**
 * 仓库无限级下拉菜单
 * $pid 上级仓库id,
 * $recursive是否无限生成
 * $level 第几层
 */
function storage_select($pid = 0, $recursive = true, $level = 0, $default = '')
{
    $db_storage = M('jxc_storage');
    $list = $db_storage->field('id,name,pid')->where("pid='{$pid}' AND status=1")->select();
    if ($list) {
        $level_nbsp = str_repeat(' ', $level * 6);
        $level++;
        foreach ($list as $val) {
            $selected = $default == $val['id'] ? "selected" : '';
            $html .= "<option value=\"{$val['id']}\" pid=\"{$val['pid']}\" {$selected} >{$level_nbsp}|--{$val['name']}</optin>";
            if ($recursive) {
                //要无限级时
                $next_html = storage_select($val['id'], $recursive, $level, $default);
                $html .= $next_html;
            }
        }
    }
    return $html;
}
Exemplo n.º 2
0
 public function add()
 {
     if ($_REQUEST['act'] == 'todo') {
         //采购单
         $db_jxc_procure = M('jxc_procure');
         $info_procure = $_REQUEST['procure'];
         $info_procure['belong_month'] = date('Ym');
         $rs = $db_jxc_procure->data($info_procure)->add();
         //把采购单信息送到财务
         $db_finances = M('jxc_finances');
         $info_finances['bank_account'] = $info_procure['bank_account'];
         $info_finances['cat_id'] = 2;
         $info_finances['out_money'] = $info_procure['total_amount'];
         $info_finances['remark'] = "支付采购单:{$info_procure['procure_num']}的款项";
         $info_finances['add_user_id'] = $_SESSION[C('USER_AUTH_KEY')];
         $info_finances['add_time'] = time();
         $db_finances->data($info_finances)->add();
         //采购单对应的产品
         $db_jxc_product = M('jxc_product');
         $db_jxc_procure_product = M('jxc_procure_product');
         $list_procure_product = $_REQUEST['list_procure_product'];
         foreach ($list_procure_product as $procure_product) {
             $procure_product['procure_num'] = $info_procure['procure_num'];
             $procure_product['add_user_id'] = $_SESSION[C('USER_AUTH_KEY')];
             $procure_product['add_time'] = time();
             $db_jxc_procure_product->data($procure_product)->add();
             //选找到产品表中是否有这个产品,如果没有就添加进去
             $product_id = $db_jxc_product->where("code='{$procure_product['code']}'")->getField('id');
             if (!$product_id) {
                 $info_product = $procure_product;
                 $db_jxc_product->data($info_product)->add();
             }
             //把产品添加进仓库
             $db_jxc_inventory = M('jxc_inventory');
             $info_inventory['update_date'] = date('Y-m-d');
             $inventory = $db_jxc_inventory->field('storage_id,code,number')->where("storage_id='{$procure_product['storage_id']}' AND code='{$procure_product['code']}'")->find();
             if ($inventory) {
                 $info_inventory['number'] = $procure_product['number'] + $inventory['number'];
                 $db_jxc_inventory->where("storage_id='{$procure_product['storage_id']}' AND code='{$procure_product['code']}'")->data($info_inventory)->save();
             } else {
                 $info_inventory['storage_id'] = $procure_product['storage_id'];
                 $info_inventory['code'] = $procure_product['code'];
                 $info_inventory['number'] = $procure_product['number'];
                 $info_inventory['add_user_id'] = $_SESSION[C('USER_AUTH_KEY')];
                 $info_inventory['add_time'] = time();
                 $db_jxc_inventory->data($info_inventory)->add();
             }
         }
         if ($rs) {
             $this->success("操作成功");
         } else {
             $this->error("操作失败");
         }
     } else {
         $product_cat_option = product_cat_select(0);
         $this->assign('product_cat_option', $product_cat_option);
         $storage_option = storage_select(0);
         $this->assign('storage_option', $storage_option);
         //供应商
         $db_supplier = M('jxc_supplier');
         $list_supplier = $db_supplier->where("status=1")->select();
         $this->assign('list_supplier', $list_supplier);
         //银行帐户
         $db_bank = M('jxc_bank');
         $list_bank_account = $db_bank->where("status=1")->select();
         $this->assign('list_bank_account', $list_bank_account);
         //采购员
         $db_user = M('user');
         $list_user = $db_user->where("status=1")->select();
         $this->assign('list_user', $list_user);
         $this->display();
     }
 }