コード例 #1
0
ファイル: get_news_local.php プロジェクト: virutmath/suckhoe
}
//authen valid - get data and save post
//var_dump($_FILES['data_picture']);
$myform = new generate_form();
$myform->addTable('news');
$myform->add('new_title', 'new_title', 0, 0, '', 1, 'Tiêu đề trống');
$myform->add('new_title_md5', 'new_title_md5', 0, 0, '', 1, '');
$myform->add('new_cat_id', 'new_cat_id', 1, 0, 0, 1);
$myform->add('new_lin_id', 'new_lin_id', 1, 0, 0, 1);
$myform->add('new_picture', 'new_picture', 0, 0, '');
$myform->add('new_teaser', 'new_teaser', 0, 0, '', 1);
$myform->add('new_tags', 'new_tags', 0, 0, '');
$myform->add('new_date', 'new_date', 1, 0, 0, 1);
$myform->add('new_active', 'new_active', 1, 0, 0, 1);
if (!$myform->checkdata()) {
    $db_insert = new db_execute_return();
    $last_id = $db_insert->db_execute($myform->generate_insert_SQL());
    unset($db_insert);
    //lưu ảnh
    if ($last_id) {
        $path_picture = generate_dir_upload($_POST['new_picture'], 'organic') . $_POST['new_picture'];
        move_uploaded_file($_FILES['data_picture']['tmp_name'], $path_picture);
        //lưu chi tiết tin
        $myform_dt = new generate_form();
        $myform_dt->addTable('news_detail');
        $myform_dt->add('ndt_id', 'last_id', 1, 1, 0);
        $myform_dt->add('ndt_content', 'ndt_content', 0, 0, '');
        $myform_dt->removeHTML(0);
        $db_insert = new db_execute($myform_dt->generate_insert_SQL());
        $total = $db_insert->total;
        unset($db_insert);
コード例 #2
0
ファイル: edit.php プロジェクト: virutmath/suckhoe
    $id_ndk = $insert_id_ndk->db_execute('INSERT INTO pharma_company (phc_name) 
                                          VALUES("' . $pha_nha_sx_name . '")');
    $myform->add('pha_nha_dk_id', 'id_ndk', 1, 1, 0);
}
$pha_nhom_duoc_ly = getValue('pha_nhom_duoc_ly', 'str', 'POST', '');
$check_id_ndl = new db_query('SELECT phg_id 
                              FROM pharma_group 
                              WHERE phg_name = "' . $pha_nhom_duoc_ly . '" 
                              LIMIT 1');
$check_id_ndl = mysqli_fetch_assoc($check_id_ndl->result);
if ($check_id_ndl && $check_id_ndl['phg_id']) {
    $check_id_ndl = $check_id_ndl['phg_id'];
    $myform->add('pha_nhom_duoc_ly_id', 'check_id_ndl', 1, 1, 0);
} else {
    //insert tên công ty vào bảng pharma_company
    $insert_id_ndl = new db_execute_return();
    $id_ndl = $insert_id_ndl->db_execute('INSERT INTO pharma_group (phg_name) 
                                          VALUES("' . $pha_nhom_duoc_ly . '")');
    $myform->add('pha_nhom_duoc_ly_id', 'id_ndl', 1, 1, 0);
}
$myform->add('pha_thanh_phan', 'pha_thanh_phan', 0, 0, '', 1);
$myform->add('pha_ham_luong', 'pha_ham_luong', 0, 0, '', 0);
$myform->add('pha_chi_dinh', 'pha_chi_dinh', 0, 0, '', 1);
$myform->add('pha_chong_chi_dinh', 'pha_chong_chi_dinh', 0, 0, '', 0);
$myform->add('pha_tuong_tac_thuoc', 'pha_tuong_tac_thuoc', 0, 0, '', 0);
$myform->add('pha_tac_dung_phu', 'pha_tac_dung_phu', 0, 0, '', 0);
$myform->add('pha_chu_y_de_phong', 'pha_chu_y_de_phong', 0, 0, '', 0);
$myform->add('pha_lieu_luong', 'pha_lieu_luong', 0, 0, '', 0);
$myform->add('pha_bao_quan', 'pha_bao_quan', 0, 0, '', 0);
$form_redirect = getValue('form_redirect', 'str', 'POST', '');
$action = getValue('action', 'str', 'POST', '');
コード例 #3
0
ファイル: ajax.php プロジェクト: virutmath/suckhoe
<?php

require_once 'inc_security.php';
$action = getValue('action', 'str', 'POST', '');
switch ($action) {
    case 'add_manifest':
        $man_name = getValue('man_name', 'str', 'POST', '', 3);
        $man_name = trim($man_name);
        $man_name = mb_strtolower($man_name, 'utf8');
        if (!$man_name) {
            exit;
        }
        $db_query = new db_query('SELECT * FROM manifest WHERE man_name = "' . $man_name . '"');
        if (!($row = mysqli_fetch_assoc($db_query->result))) {
            $db_insert = new db_execute_return();
            $last_id = $db_insert->db_execute('INSERT INTO manifest(man_name) VALUE("' . $man_name . '")');
            echo json_encode(array('success' => 1, 'man_id' => $last_id, 'man_name' => $man_name));
            exit;
        }
        break;
}
コード例 #4
0
ファイル: ajax.php プロジェクト: virutmath/crm_local
 function billSubmit()
 {
     global $configuration, $admin_id;
     $array_return = array();
     //kiểm tra xem có hóa đơn nào thực hiện ko, nếu có thì exit luôn
     $db_trigger = new db_query('SELECT tri_status FROM triggers WHERE tri_key = "billSubmit" LIMIT 1');
     $trigger = mysqli_fetch_assoc($db_trigger->result);
     unset($db_trigger);
     if ($trigger['tri_status'] == 1) {
         //đang có hóa đơn được thanh toán, exit luôn
         $array_return['error'] = 'Đang có hóa đơn khác được thanh toán, bạn vui lòng thử lại trong giây lát!';
         $this->add($array_return);
         return false;
     }
     //bắt đầu xử lý hàm submit hóa đơn
     $desk_id = getValue('desk_id', 'int', 'POST', 0);
     check_desk_exist($desk_id);
     if (!$desk_id) {
         $array_return['error'] = 'Bàn chưa được mở';
         $this->add($array_return);
         return false;
     }
     //kiểm tra xem bàn có thực đơn nào không?
     $db_count = new db_count('SELECT count(*) AS count FROM current_desk_menu WHERE cdm_desk_id = ' . $desk_id);
     if (!$db_count->total) {
         $array_return['error'] = 'Không thể thanh toán hóa đơn trống';
         $this->add($array_return);
         return false;
     }
     //Kiểm tra tồn kho
     $db_desk = new db_query('SELECT
                              *
                             FROM
                                 current_desk
                             LEFT JOIN current_desk_menu ON cud_desk_id = cdm_desk_id
                             WHERE cud_desk_id = ' . $desk_id);
     //mảng lưu list id thực đơn của bàn hiện tại
     $list_menu = array();
     //mảng lưu list số lượng tương ứng với từng thực đơn
     $list_quantity = array();
     //mảng lưu id của các thực đơn ko đủ số lượng tồn
     $disallow_menu = array();
     //mảng lưu thông tin về bàn
     $desk_detail = array();
     //mảng lưu thông tin về các thực đơn trong bàn
     $desk_menu_detail = array();
     while ($row = mysqli_fetch_assoc($db_desk->result)) {
         $desk_detail = $row;
         $desk_menu_detail[] = $row;
         $list_menu[] = $row['cdm_menu_id'];
         $list_quantity[$row['cdm_menu_id']] = $row['cdm_number'];
     }
     //lấy ra mảng số lượng tồn kho
     $allow_quantity = $this->calculateInventoryMenu($list_menu);
     //lặp qua mảng tồn kho để kiểm tra xem số lượng có đủ ko
     foreach ($allow_quantity as $men_id => $men_quantity) {
         if ($men_quantity < $list_quantity[$men_id]) {
             $disallow_menu[] = $men_id;
         }
     }
     //tinh tong tien can phai tra cua hoa don
     //mảng lưu tổng tiền của từng thực đơn trong bàn key=>value trong đó key : id thực đơn, value : tổng tiền thực đơn đó
     $array_money = array();
     //mảng lưu đơn giá của thực đơn
     $array_price = array();
     foreach ($desk_menu_detail as $cd_menu) {
         //select ra thong tin ve gia cua menu
         //neu menu duoc custom gia thi gia cua menu la gia cdm_price
         //neu menu khong duoc custom gia thi gia cua menu lay tu bang menu dua vao cdm_price_type
         $db_check = new db_query('SELECT men_editable, men_price, men_price1, men_price2
                                       FROM menus
                                       WHERE men_id = ' . $cd_menu['cdm_menu_id']);
         $cd_menu_detail = mysqli_fetch_assoc($db_check->result);
         unset($db_check);
         if ($cd_menu_detail['men_editable']) {
             //thực đơn cho phép chỉnh sửa giá : lấy giá của thực đơn trong cdm_price
             $array_money[$cd_menu['cdm_menu_id']] = $cd_menu['cdm_price'] * (1 - $cd_menu['cdm_menu_discount'] / 100) * $cd_menu['cdm_number'];
             $array_price[$cd_menu['cdm_menu_id']] = $cd_menu['cdm_price'];
         } else {
             //thực đơn không cho phép chỉnh sửa giá : lấy giá thực đơn theo cdm_price_type
             $array_money[$cd_menu['cdm_menu_id']] = $cd_menu_detail[$cd_menu['cdm_price_type']] * (1 - $cd_menu['cdm_menu_discount'] / 100) * $cd_menu['cdm_number'];
             $array_price[$cd_menu['cdm_menu_id']] = $cd_menu_detail[$cd_menu['cdm_price_type']];
         }
     }
     //kiểm tra ngày trả nợ - nếu nhỏ hơn ngày hiện tại thì đưa ra thông báo lỗi
     $debit = getValue('debit', 'int', 'POST', 0);
     $date_debit = getValue('date', 'str', 'POST', '');
     $date_debit = convertDateTime($date_debit, '0:0:0');
     if ($debit) {
         //có ghi nợ - kiểm tra ngày trả nợ
         if ($date_debit < time()) {
             $array_return['error'] = 'Ngày hẹn trả không phù hợp';
             $this->add($array_return);
             return false;
         }
     }
     //Kiểm tra xem có cho phép xuất âm kho hàng không
     //Hiện tại trong config không cho phép xuất âm - làm dần dần
     if (count($disallow_menu) > 0 && !$configuration['con_negative_export']) {
         //thực đơn không đủ số lượng tồn kho, đưa ra thông báo lỗi
         $array_return['error'] = 'Không thể xuất do không đủ số lượng tồn kho';
         $array_return['disallow_menu'] = json_encode($disallow_menu);
         $this->add($array_return);
         return false;
     } else {
         //Không có hóa đơn nào đang được xử lý - cập nhật trigger status thành 1 để bắt đầu vào hàm
         $db_update = new db_execute('UPDATE triggers SET tri_status = 1 WHERE tri_key = "billSubmit" LIMIT 1');
         unset($db_update);
         //bắt đầu tạo và thanh toán hóa đơn
         //trừ số lượng sản phẩm trong hóa đơn vào kho hàng
         foreach ($list_menu as $men_id) {
             //lấy ra các sản phẩm có trong thực đơn, sau đó trừ đi
             $db_product = new db_query('SELECT *
                                         FROM menu_products
                                         LEFT JOIN product_quantity ON product_id = mep_product_id
                                         WHERE mep_menu_id = ' . $men_id . '
                                         AND store_id = ' . $configuration['con_default_store']);
             while ($row_pro = mysqli_fetch_assoc($db_product->result)) {
                 $sql_minus = 'UPDATE product_quantity
                               SET pro_quantity = pro_quantity - ' . $row_pro['mep_quantity'] * $list_quantity[$row_pro['mep_menu_id']] . '
                               WHERE product_id = ' . $row_pro['product_id'] . ' AND store_id = ' . $configuration['con_default_store'];
                 $db_update = new db_execute($sql_minus);
                 unset($db_update);
             }
         }
         //sau khi trừ xong sản phẩm thì insert vào bảng thu chi và bảng hóa đơn
         //insert vào bảng hóa đơn bán hàng bill_in
         //giờ vào bàn
         $bii_start_time = $desk_detail['cud_start_time'];
         //giờ đóng bàn
         $bii_end_time = time();
         //id của bàn
         $bii_desk_id = $desk_id;
         //id kho xuất hàng
         $bii_store_id = $configuration['con_default_store'];
         //id quầy phục vụ
         $bii_service_desk_id = $configuration['con_default_svdesk'];
         //id khách hàng
         $bii_customer_id = $desk_detail['cud_customer_id'];
         //id nhân viên bán hàng
         $bii_staff_id = $desk_detail['cud_staff_id'];
         //id thu ngân - người lập hóa đơn
         $bii_admin_id = $admin_id;
         //loại thanh toán - tiền mặt hay thẻ.
         $bii_type = getValue('payType', 'int', 'POST', PAY_TYPE_CASH);
         $bii_type = $bii_type == PAY_TYPE_CASH ? PAY_TYPE_CASH : PAY_TYPE_CARD;
         //phụ phí
         $bii_extra_fee = $desk_detail['cud_extra_fee'];
         //thue VAT
         $bii_vat = $desk_detail['cud_vat'];
         //giam gia
         $bii_discount = $desk_detail['cud_customer_discount'];
         //tong tien
         $bii_true_money = 0;
         foreach ($array_money as $key => $money) {
             $bii_true_money += $money;
         }
         //tính giảm giá, thuế và phụ phí để ra số tiền thực tế
         $bii_true_money = $bii_true_money * (100 - $bii_discount + $bii_extra_fee) / 100 * (100 + $bii_vat) / 100;
         //tiền làm tròn
         $bii_round_money = round($bii_true_money, -3);
         if ($debit && $debit < $bii_true_money) {
             $bii_status = BILL_STATUS_DEBIT;
             $bii_money_debit = $bii_true_money - $debit;
             $bii_date_debit = $date_debit;
         } else {
             $bii_status = BILL_STATUS_SUCCESS;
             $bii_money_debit = 0;
             $bii_date_debit = 0;
         }
         //insert vào bảng bill_in
         $sql_insert = 'INSERT INTO bill_in (
                             bii_start_time,
                             bii_end_time,
                             bii_desk_id,
                             bii_store_id,
                             bii_customer_id,
                             bii_staff_id,
                             bii_admin_id,
                             bii_status,
                             bii_type,
                             bii_extra_fee,
                             bii_vat,
                             bii_discount,
                             bii_true_money,
                             bii_round_money,
                             bii_service_desk_id,
                             bii_money_debit,
                             bii_date_debit
                         )
                         VALUES (
                         ' . $bii_start_time . ',
                         ' . $bii_end_time . ',
                         ' . $bii_desk_id . ',
                         ' . $bii_store_id . ',
                         ' . $bii_customer_id . ',
                         ' . $bii_staff_id . ',
                         ' . $bii_admin_id . ',
                         ' . $bii_status . ',
                         ' . $bii_type . ',
                         ' . $bii_extra_fee . ',
                         ' . $bii_vat . ',
                         ' . $bii_discount . ',
                         ' . $bii_true_money . ',
                         ' . $bii_round_money . ',
                         ' . $bii_service_desk_id . ',
                         ' . $bii_money_debit . ',
                         ' . $bii_date_debit . '
                         )';
         $db_insert = new db_execute_return();
         $bill_success_id = $db_insert->db_execute($sql_insert);
         //insert chi tiết hóa đơn vào bảng bill_in_detail
         $sql_insert = 'INSERT INTO bill_in_detail (
                           bid_bill_id,
                           bid_menu_id,
                           bid_menu_discount,
                           bid_menu_number,
                           bid_menu_price
                        ) VALUES ';
         foreach ($desk_menu_detail as $cd_menu) {
             $sql_insert .= '(
             ' . $bill_success_id . ',
             ' . $cd_menu['cdm_menu_id'] . ',
             ' . $cd_menu['cdm_menu_discount'] . ',
             ' . $cd_menu['cdm_number'] . ',
             ' . $array_price[$cd_menu['cdm_menu_id']] . '),';
         }
         $sql_insert = rtrim($sql_insert, ',');
         $db_insert = new db_execute($sql_insert);
         unset($db_insert);
         //phát sinh 1 phiếu thu - insert dữ liệu vào phiếu thu
         //logic : hóa đơn ghi nợ thì phát sinh phiếu thu với 1 phần số tiền đã thu. hóa đơn trả đủ thì insert bình thường
         $fin_money = $bii_true_money;
         if ($debit) {
             $fin_money = $bii_true_money - $bii_money_debit;
         }
         //làm tròn số
         $fin_money = round($fin_money);
         //lấy thông tin khách hàng
         if ($bii_customer_id) {
             $db_customer = new db_query('SELECT * FROM customers WHERE cus_id = ' . $bii_customer_id . ' LIMIT 1');
             $customer = mysqli_fetch_assoc($db_customer->result);
             $fin_username = $customer['cus_name'];
             $fin_address = $customer['cus_address'];
         } else {
             $fin_username = '******';
             $fin_address = '';
         }
         $sql_insert = 'INSERT INTO financial
                         (fin_date, fin_updated_time, fin_money, fin_reason_other,
                         fin_billcode, fin_username, fin_address, fin_cat_id,
                         fin_pay_type, fin_note, fin_admin_id, fin_agency_id)
                         VALUES
                         (
                         ' . $bii_end_time . ',
                         ' . $bii_end_time . ',
                         ' . $fin_money . ',
                         "Bán hàng",
                         "' . $bill_success_id . '",
                         "' . $fin_username . '",
                         "' . $fin_address . '",
                         ' . FINANCIAL_CAT_BAN_HANG . ',
                         ' . $bii_type . ',
                         "",
                         ' . $admin_id . ',
                         ' . $configuration['con_default_agency'] . '
                         )';
         $db_insert = new db_execute($sql_insert);
         if ($db_insert->total) {
             //thanh toán xong thì xóa bàn
             $db_delete_desk = new db_execute('DELETE FROM current_desk WHERE cud_desk_id = ' . $desk_id);
             $db_delete_desk = new db_execute('DELETE FROM current_desk_menu WHERE cdm_desk_id = ' . $desk_id);
             unset($db_insert, $db_delete_desk);
             //return lại mã hóa đơn
             $array_return['success'] = 1;
             $array_return['bii_id'] = $bill_success_id;
         } else {
             $array_return['error'] = 'Lỗi không rõ lý do';
         }
     }
     //thực hiện update trigger về 0 để giải phóng function
     $db_update = new db_execute('UPDATE triggers SET tri_status = 0 WHERE tri_key = "billSubmit" LIMIT 1');
     unset($db_update);
     //trả kết quả về client
     $this->add($array_return);
 }
コード例 #5
0
ファイル: index.php プロジェクト: virutmath/crm_local
     $db_unit_id = $db_insert_unit->db_execute("INSERT INTO units\n                                                                (\n                                                                uni_name, \n                                                                uni_note\n                                                                ) VALUES (\n                                                                '" . $uni_name . "',\n                                                                '" . $uni_note . "'\n                                                                )");
     $pro_unit_id = $db_unit_id;
     unset($db_insert_unit);
 }
 unset($db_unit);
 // kiem tra trong csdl ton tai nguyen lieu nay chua
 // neu co roi thi lay ra id
 // neu chua co thi insert vao song lay ra id
 $dbPro = new db_query("SELECT pro_id FROM products \n                                        WHERE pro_name = '" . trim($pro_name) . "'");
 //neu co roi
 if (mysqli_num_rows($dbPro->result) >= 1) {
     $dataPro = mysqli_fetch_assoc($dbPro->result);
     //lay ra id cua nguyen lieu
     $idPro = $dataPro['pro_id'];
 } else {
     $db_insert_product = new db_execute_return();
     $db_product_id = $db_insert_product->db_execute("INSERT INTO products\n                                                                        (\n                                                                        pro_name, \n                                                                        pro_image, \n                                                                        pro_note, \n                                                                        pro_cat_id,\n                                                                        pro_unit_id, \n                                                                        pro_code, \n                                                                        pro_instock, \n                                                                        pro_status\n                                                                        ) \n                                                                        VALUES \n                                                                        (\n                                                                        '" . trim($pro_name) . "',\n                                                                        '" . $pro_image . "',\n                                                                        '" . $pro_note . "',\n                                                                        " . $pro_cat_id . ",\n                                                                        " . $pro_unit_id . ",\n                                                                        '" . $pro_code . "',\n                                                                        " . $pro_instock . ",\n                                                                        " . $pro_status . "\n                                                                        )");
     unset($db_insert_product);
     $idPro = $db_product_id;
 }
 unset($dbPro);
 // co id product roi
 // lay ra id cua tat ca cac kho cua cua hang
 //$arrStore_id = array();
 //                $db_store = new db_query ("SELECT * FROM categories_multi
 //                                           WHERE cat_type = '" . STORE_CAT_TYPE . "'");
 //                while ( $data_store = mysqli_fetch_assoc($db_store->result) )
 //                {
 //                    $arrStore_id[] = $data_store['cat_id'];
 //                }
 //
コード例 #6
0
ファイル: add.php プロジェクト: nhphong0104/thietkeweb360
#+ đổi tên trường thành biến và giá trị
$myform->evaluate();

#+
#+ Neu nhu co submit form
if($action == "submitForm"){

	#+
	#+ Kiểm tra lỗi
    $errorMsg .= $myform->checkdata();
	$errorMsg .= $myform->strErrorField ;	//Check Error!
	if($errorMsg == ""){

		#+
		#+ Thuc hien query
		$db_ex	 		= new db_execute_return();
		$query			= $myform->generate_insert_SQL();
		$last_id 		= $db_ex->db_execute($query);
		$record_id 		= $last_id;
		//echo $query;exit();

		$iType			= getValue("mnu_type","int","POST","");
		$iParent		= getValue("mnu_parent_id","str","POST","");
		$fs_redirect 	= $after_save_data. "?record_id=".$record_id."&category=".getValue("sta_category_id","int","POST");
		redirect($fs_redirect);
		exit();

	}
}

#+
コード例 #7
0
            $db_insert_product = new db_execute_return();
            $db_product_id = $db_insert_product->db_execute("INSERT INTO products\n                                                                (\n                                                                pro_name, \n                                                                pro_image, \n                                                                pro_note, \n                                                                pro_cat_id,\n                                                                pro_unit_id, \n                                                                pro_code, \n                                                                pro_instock, \n                                                                pro_status\n                                                                ) \n                                                                VALUES \n                                                                (\n                                                                '" . trim($pro_name) . "',\n                                                                '" . $pro_image . "',\n                                                                '" . $pro_note . "',\n                                                                " . $pro_cat_id . ",\n                                                                " . $pro_unit_id . ",\n                                                                '" . $pro_code . "',\n                                                                " . $pro_instock . ",\n                                                                " . $pro_status . "\n                                                                )");
            unset($db_insert_product);
            $idPro = $db_product_id;
        }
        unset($dbPro);
        $pro_quantity = 0;
        // thêm nguyên liệu vào bảng product quantity
        $db_store = new db_query("SELECT * FROM categories_multi\n                                    WHERE cat_type = 'stores'");
        while ($data_store = mysqli_fetch_assoc($db_store->result)) {
            $db_product_quantity = new db_query("SELECT * FROM product_quantity\n                                                  WHERE product_id = " . $idPro . "\n                                                  AND store_id = " . $data_store['cat_id']);
            if (mysqli_num_rows($db_product_quantity->result) >= 1) {
                $db_update_product_quantity = new db_execute("UPDATE product_quantity \n                                                              SET \n                                                              pro_quantity= pro_quantity + " . $pro_quantity . "\n                                                              WHERE product_id = " . $idPro . "\n                                                              AND store_id = " . $data_store['cat_id']);
                unset($db_update_product_quantity);
            } else {
                $db_insert_product_quantity = new db_execute_return();
                $db_product_quantity = $db_insert_product_quantity->db_execute("INSERT INTO product_quantity\n                                                                                (\n                                                                                product_id, \n                                                                                store_id, \n                                                                                pro_quantity\n                                                                                ) VALUES (\n                                                                                " . $idPro . ",\n                                                                                " . $data_store['cat_id'] . ",\n                                                                                " . $pro_quantity . "\n                                                                                )");
                unset($db_insert_product_quantity);
            }
            unset($db_product_quantity);
        }
        $db_menu_quantity = new db_query("SELECT * FROM menu_products \n                                           WHERE mep_menu_id = " . $menu_id . "\n                                           AND mep_product_id = " . $idPro . "");
        if (mysqli_num_rows($db_menu_quantity->result) == 0) {
            $sql_menu_products = new db_execute("INSERT INTO menu_products\n                                                (\n                                                mep_menu_id, \n                                                mep_product_id, \n                                                mep_quantity\n                                                ) \n                                                VALUES(\n                                                " . $menu_id . ",\n                                                " . $idPro . ",\n                                                " . floatval($mep_quantity) . "\n                                                )");
            unset($sql_menu_products);
        }
    }
}
?>
<h3>Import danh sách thực đơn bánh và nguyên liệu</h3>
<form action="" method="post" enctype="multipart/form-data" id="update-menu" name="update_menu">
コード例 #8
0
ファイル: ajax.php プロジェクト: virutmath/crm_local
 function AddRecord()
 {
     global $time_end, $time_start;
     //check quyền
     checkCustomPermission('add');
     // ten chien dich khuyen mai
     $promo_name = getValue('name', 'str', 'POST', '');
     if (!$promo_name) {
         $array_return['error'] = 0;
         $array_return['msg'] = 'Chưa nhập tên chiến dịch khuyến mại';
         die(json_encode($array_return));
     }
     $promo_agencies = getValue('agencies', 'int', 'POST', 0, 3);
     // thoi gian bat dau
     $start_time = getValue('start_date', 'str', 'POST', '', 3);
     $time_start_h = getValue('time_start_h', 'int', 'POST', 0, 3);
     $time_start_i = getValue('time_start_i', 'int', 'POST', 0, 3);
     //thoi gian ket thuc
     $end_time = getValue('end_date', 'str', 'POST', '', 3);
     $time_end_h = getValue('time_end_h', 'int', 'POST', 0, 3);
     $time_end_i = getValue('time_end_i', 'int', 'POST', 0, 3);
     // ghi chú
     $promo_note = getValue('note', 'str', 'POST', '', 3);
     $list_menus = getValue('menus', 'arr', 'POST', array());
     // dieu kien giam gia
     $promo_condition = getValue('condition', 'int', 'POST', 0, 3);
     // gia tri giảm giá hóa đơn dựa vào kiểu giảm giá promo_type có 2 giá trị là % và tiền mặt
     $promo_value = getValue('promo_value', 'int', 'POST', 0, 3);
     $promo_type = getValue('promo_type', 'int', 'POST', 0, 3);
     $time_start = convertDateTime($start_time, $time_start_h . ':' . $time_start_i . ':0');
     if (!$time_start) {
         $array_return['error'] = 0;
         $array_return['msg'] = 'Chưa nhập thời gian bắt đầu chiến dịch';
         die(json_encode($array_return));
     }
     $time_end = convertDateTime($end_time, $time_end_h . ':' . $time_end_i . ':0');
     if (!$time_end) {
         $array_return['error'] = 0;
         $array_return['msg'] = 'Chưa nhập thời gian kết thúc chiến dịch';
         die(json_encode($array_return));
     }
     if (!$list_menus && !$promo_value) {
         $array_return['error'] = 0;
         $array_return['msg'] = 'Chương trình khuyến mại không phù hợp';
         die(json_encode($array_return));
     }
     // insert chiến dịch khuyến mãi
     $myform = new generate_form();
     $myform->addTable('promotions');
     $myform->add('pms_name', 'name', 0, 0, $promo_name, 1, 'Bạn chưa nhập tên chiến dịch');
     $myform->add('pms_agency_id', 'agencies', 1, 0, $promo_agencies, 1, 'Bạn chưa chọn địa điểm áp dụng');
     $myform->add('pms_start_time', 'time_start', 0, 1, $time_start, 1, 'Thời gian bắt đầu chưa nhập');
     $myform->add('pms_end_time', 'time_end', 0, 1, $time_end, 1, 'Thời gian kết thúc chưa nhập');
     $myform->add('pms_value_sale', 'promo_value', 1, 0, $promo_value, 0);
     $myform->add('pms_type_sale', 'promo_type', 1, 0, $promo_type, 0);
     $myform->add('pms_condition', 'condition', 1, 0, $promo_condition, 0);
     $myform->add('pms_note', 'note', 0, 0, $promo_note, 0);
     if (!$myform->checkdata()) {
         $db_insert = new db_execute_return();
         $last_id = $db_insert->db_execute($myform->generate_insert_SQL());
         unset($db_insert);
         if (!$last_id) {
             //lỗi
             $array_return['error'] = 0;
             $array_return['msg'] = 'Đã có lỗi xảy ra. Vui lòng thử lại sau';
             $array_return['success'] = 1;
             die(json_encode($array_return));
         }
         $db_promo_menu = 'INSERT INTO promotions_menu(pms_id ,pms_menu_id, pms_menu_value, pms_menu_type)
                        VALUES';
         //sử dụng id của promotion để insert vào bảng promotions_menu
         foreach ($list_menus as $menu) {
             $db_promo_menu .= '(
                        ' . $last_id . ',
                        ' . $menu['men_id'] . ',
                        ' . $menu['men_value'] . ',
                        ' . $menu['men_type'] . '
                        ),';
         }
         $db_promo_menu = rtrim($db_promo_menu, ',');
         $db_insert_menu = new db_execute($db_promo_menu);
         unset($db_insert_menu);
         //log action
         log_action(ACTION_LOG_ADD, 'Thêm mới chiến dịch ' . $last_id . ' bảng promotions');
         $array_return = array('success' => 1, 'msg' => 'Thêm mới thành công');
         die(json_encode($array_return));
     }
 }
コード例 #9
0
ファイル: ajax.php プロジェクト: virutmath/crm_local
 function stock_transfer()
 {
     //id nguoi kiem ke
     $staff_id = getValue('staff_id', 'int', 'POST', 0);
     if (!$staff_id) {
         $array_return = array('error' => 0, 'msg' => 'Bạn chưa nhập tên nhân viên');
         die(json_encode($array_return));
     }
     $from_store = getValue('from_store', 'int', 'POST', 0);
     if (!$from_store) {
         $array_return = array('error' => 0, 'msg' => 'Bạn chưa chọn chuyển từ kho');
         die(json_encode($array_return));
     }
     $to_store = getValue('to_store', 'int', 'POST', 0);
     if (!$to_store) {
         $array_return = array('error' => 0, 'msg' => 'Bạn chưa chọn chuyển đến kho');
         die(json_encode($array_return));
     }
     if ($from_store == $to_store) {
         $array_return = array('error' => 0, 'msg' => 'Chuyển kho không hợp lệ');
         die(json_encode($array_return));
     }
     $note = getValue('note', 'str', 'POST', '');
     $products = getValue('products', 'arr', 'POST', '');
     if (!$products) {
         $array_return = array('error' => 0, 'msg' => 'Bạn chưa chọn mặt hàng chuyển kho');
         die(json_encode($array_return));
     }
     //thời gian mặc định tạo phiếu
     $default_time = time();
     global $admin_id;
     // thêm thông tin vào phiếu chuyển kho hàng
     $myform = new generate_form();
     $myform->addTable('stock_transfer');
     $myform->add('sto_staff_id', 'staff_id', 1, 0, $staff_id, 1, 'Bạn chưa nhập tên nhân viên');
     $myform->add('sto_from_storeid', 'from_store', 1, 0, $from_store, 1, 'Bạn chưa chọn chuyển từ kho');
     $myform->add('sto_to_storeid', 'to_store', 1, 0, $to_store, 1, 'Bạn chưa chọn kho chuyển đến');
     $myform->add('sto_time', 'sto_time', 1, 0, $default_time, 0);
     $myform->add('sto_note', 'note', 0, 0, $note, '');
     $myform->add('sto_admin_id', 'admin_id', 1, 0, $admin_id, 0);
     if (!$myform->checkdata()) {
         $db_insert = new db_execute_return();
         $last_id = $db_insert->db_execute($myform->generate_insert_SQL());
         unset($db_insert);
         if (!$last_id) {
             //lỗi
             $array_return = array('error' => 0, 'msg' => 'Đã có lỗi xảy ra! Vui lòng thử lại sau');
             die(json_encode($array_return));
         }
         // insert sản phẩm được chuyển với số lượng trước khi chuyển và sau khi chuyển
         $db_product_menu = 'INSERT INTO stock_transfer_products(sto_id ,pro_id, stp_quantity_inventory, stp_quantity_transfer)
                             VALUES';
         //sử dụng id của stock_transfer để insert vào bảng stock_transfer_products
         foreach ($products as $product) {
             $db_product_menu .= '(
                    ' . $last_id . ',
                    ' . $product['pro_id'] . ',
                    ' . $product['pro_quantity'] . ',
                    ' . $product['pro_quantity_transfer'] . '
                    ),';
         }
         $db_product_menu = rtrim($db_product_menu, ',');
         $db_insert_product = new db_execute($db_product_menu);
         unset($db_insert_product);
         //log action
         log_action(ACTION_LOG_ADD, 'Thêm mới danh sách hàng chuyển kho ' . $last_id . ' bảng stock_transfer');
         // update lại số lượng trong bảng product_quantity sau khi chuyển kho
         foreach ($products as $product) {
             $db_from_store = 'UPDATE product_quantity SET  pro_quantity = pro_quantity - ' . $product['pro_quantity_transfer'] . '
                                    WHERE store_id = ' . $from_store . '
                                    AND product_id = ' . $product['pro_id'] . ',';
             $db_from_store = rtrim($db_from_store, ',');
             $product_from_store = new db_execute($db_from_store);
             unset($product_from_store);
             $db_to_store = 'UPDATE product_quantity SET  pro_quantity = pro_quantity + ' . $product['pro_quantity_transfer'] . '
                                    WHERE store_id = ' . $to_store . '
                                    AND product_id = ' . $product['pro_id'] . ',';
             $db_to_store = rtrim($db_to_store, ',');
             $product_to_store = new db_execute($db_to_store);
             unset($product_to_store);
         }
         //log action
         log_action(ACTION_LOG_EDIT, 'Update số lượng hàng với mã phiếu chuyển kho là  ' . $last_id . ' bảng product_quantity');
         $array_return = array('success' => 1, 'msg' => 'Thêm mới thành công');
         die(json_encode($array_return));
     }
 }
コード例 #10
0
ファイル: ajax.php プロジェクト: virutmath/crm_local
 function payDebit()
 {
     checkPermission('edit');
     $id_object = getValue('id_object', 'int', 'POST', 0);
     $type_object = getValue('type_object', 'str', 'POST', '');
     $next_money_pay = getValue('next_money_pay', 'int', 'POST', 0);
     $type_pay = getValue('type_pay', 'int', 'POST', 0);
     $ghichu = getValue('ghichu', 'str', 'POST', '');
     //
     global $admin_id, $configuration;
     $tabel_bill = '';
     $table_left_join = '';
     $bill_id = '';
     $status = '';
     $id_obj = '';
     $debit = '';
     $table_financy = '';
     $type_debit = '';
     $name_object = '';
     $address_object = '';
     $cat_id = 0;
     $result = array();
     $table_financy = 'financial';
     $array_return = array();
     if ($id_object && $type_object && $next_money_pay) {
         // neu nhan duoc kieu hoa don la customer
         if (trim($type_object) == 'customer') {
             $tabel_bill = 'bill_in';
             $table_left_join = 'LEFT JOIN customers ON bii_customer_id = cus_id ';
             $bill_id = 'bii_id';
             $status = 'bii_status';
             $id_obj = 'bii_customer_id';
             $debit = 'bii_money_debit';
             $type_debit = 'Công nợ khách hàng';
             $name_object = 'cus_name';
             $address_object = 'cus_address';
             $cat_id = FINANCIAL_CAT_CONG_NO_BAN_HANG;
         }
         // neu nhan duoc kieu hoa don la supplier
         if (trim($type_object) == 'supplier') {
             $tabel_bill = 'bill_out';
             $table_left_join = 'LEFT JOIN suppliers ON bio_supplier_id = sup_id ';
             $bill_id = 'bio_id';
             $status = 'bio_status';
             $id_obj = 'bio_supplier_id';
             $debit = 'bio_money_debit';
             $type_debit = 'Công nợ nhà cung cấp';
             $name_object = 'sup_name';
             $address_object = 'sup_address';
             $cat_id = FINANCIAL_CAT_CONG_NO_NHAP_HANG;
         }
         $db_pay_debit = new db_query('SELECT * FROM ' . $tabel_bill . ' ' . $table_left_join . '
                                         WHERE ' . $status . ' <> ' . BILL_STATUS_SUCCESS . ' 
                                         AND ' . $id_obj . ' = ' . $id_object . '
                                         AND ' . $debit . ' <> ' . BILL_STATUS_DEBIT);
         $db_num = mysqli_num_rows($db_pay_debit->result);
         if ($db_num) {
             while ($data_bill = mysqli_fetch_assoc($db_pay_debit->result)) {
                 //$result[]       = $data_bill;
                 //quá trình thực hiện
                 //nếu $next_money_pay > 0
                 // nếu số nợ của hóa đơn nhỏ hơn hoặc bằng số tiền khách trả thì thực hiện trừ tiền trong next_money_pay
                 if ($next_money_pay > 0 && $next_money_pay >= $data_bill[$debit]) {
                     //trừ tiền thành công tiến hành cập nhật lại hóa đơn
                     $db_update_bill = new db_execute('UPDATE ' . $tabel_bill . ' 
                                                         SET 
                                                         ' . $debit . ' = ' . BILL_STATUS_DEBIT . ', 
                                                         ' . $status . ' = ' . BILL_STATUS_SUCCESS . '
                                                         WHERE ' . $bill_id . ' = ' . $data_bill[$bill_id]);
                     if ($db_update_bill->total) {
                         //thành công
                         $array_return['success'] = 'thành công';
                     }
                     unset($db_update_bill);
                     //phát sinh 1 phiếu trong financies
                     $db_insert_financy = new db_execute_return();
                     $last_id_financy = $db_insert_financy->db_execute('INSERT INTO ' . $table_financy . '
                                                                         (
                                                                         fin_date, 
                                                                         fin_updated_time, 
                                                                         fin_money, 
                                                                         fin_reason_other, 
                                                                         fin_billcode, 
                                                                         fin_username, 
                                                                         fin_address, 
                                                                         fin_cat_id, 
                                                                         fin_pay_type, 
                                                                         fin_note, 
                                                                         fin_admin_id,
                                                                         fin_agency_id
                                                                         ) 
                                                                         VALUES 
                                                                         (
                                                                         ' . time() . ', 
                                                                         ' . time() . ', 
                                                                         ' . $data_bill[$debit] . ', 
                                                                         "' . $type_debit . '", 
                                                                         ' . $data_bill[$bill_id] . ', 
                                                                         "' . $data_bill[$name_object] . '", 
                                                                         "' . $data_bill[$address_object] . '", 
                                                                         ' . $cat_id . ', 
                                                                         ' . $type_pay . ', 
                                                                         "' . $ghichu . '", 
                                                                         ' . $admin_id . ',
                                                                         ' . $configuration['con_default_agency'] . '
                                                                         )
                                                                         ');
                     unset($db_insert_financy);
                     //thực hiện trừ tiền trong số khách trả
                     $next_money_pay = $next_money_pay - $data_bill[$debit];
                     continue;
                 }
                 // nếu số tiền khách trả lớn hơn 0 và nhỏ hơn số nợ trong hóa đơn thì thực hiện lấy số tiền nợ trong hóa đơn - cho số khách trả
                 // cập nhật lại số tiền nợ còn lại sau khi trừ
                 if ($next_money_pay > 0 && $next_money_pay < $data_bill[$debit]) {
                     $db_update_bill = new db_execute('UPDATE ' . $tabel_bill . ' 
                                                         SET ' . $debit . ' = ' . $debit . ' - ' . $next_money_pay . ' 
                                                         WHERE ' . $bill_id . ' = ' . $data_bill[$bill_id]);
                     if ($db_update_bill->total) {
                         //thành công
                         $array_return['success'] = 'thành công';
                     }
                     unset($db_update_bill);
                     // cũng phát sinh 1 phiếu trong financies
                     $db_insert_financy = new db_execute_return();
                     $last_id_financy = $db_insert_financy->db_execute('INSERT INTO ' . $table_financy . '
                                                                         (
                                                                         fin_date, 
                                                                         fin_updated_time, 
                                                                         fin_money, 
                                                                         fin_reason_other, 
                                                                         fin_billcode, 
                                                                         fin_username, 
                                                                         fin_address, 
                                                                         fin_cat_id, 
                                                                         fin_pay_type, 
                                                                         fin_note, 
                                                                         fin_admin_id,
                                                                         fin_agency_id
                                                                         ) 
                                                                         VALUES 
                                                                         (
                                                                         ' . time() . ', 
                                                                         ' . time() . ', 
                                                                         ' . $next_money_pay . ', 
                                                                         "' . $type_debit . '", 
                                                                         ' . $data_bill[$bill_id] . ', 
                                                                         "' . $data_bill[$name_object] . '", 
                                                                         "' . $data_bill[$address_object] . '", 
                                                                         ' . $cat_id . ', 
                                                                         ' . $type_pay . ', 
                                                                         "' . $ghichu . '", 
                                                                         ' . $admin_id . ',
                                                                         ' . $configuration['con_default_agency'] . '
                                                                         )
                                                                         ');
                     // lúc này số tiền khách trả sẽ còn 0;
                     $next_money_pay = 0;
                     continue;
                 }
                 if ($next_money_pay == 0) {
                     break;
                 }
             }
         }
         echo json_encode($array_return);
         unset($db_pay_debit);
     }
 }
コード例 #11
0
ファイル: ajax.php プロジェクト: virutmath/crm_local
 function ADDbill()
 {
     checkPermission('add');
     $typePrice = getValue('typePrice', 'str', 'POST', '');
     $deskID = getValue('deskID', 'int', 'POST', 0);
     $numberMenu = getValue('numberMenu', 'int', 'POST', 0);
     $idMenu = getValue('idMenu', 'int', 'POST', 0);
     $men_price = getValue('men_price', 'int', 'POST', 0);
     if ($typePrice == '' || $deskID == 0 || $numberMenu == 0 || $idMenu == 0) {
         $array_return['success'] = 0;
         echo json_encode($array_return);
         exit;
     }
     //tạm thời chưa có chương trình khuyến mại gán $cdm_menu_dis_count = 0
     $cdm_menu_discount = 0;
     // kiem tra xem mon vua goi da ton tai hay
     $db_current_desk_menu = new db_query("SELECT * FROM current_desk_menu\n                                                        WHERE cdm_desk_id = " . intval($deskID) . "\n                                                        AND cdm_menu_id = " . intval($idMenu) . "");
     // neu ton tai roi thi update so luong
     if (mysqli_num_rows($db_current_desk_menu->result) >= 1) {
         $db_update_menu_number = new db_execute("UPDATE current_desk_menu \n                                                            SET cdm_number = cdm_number + " . intval($numberMenu) . ",\n                                                            cdm_price = " . intval($men_price) . ",\n                                                            cdm_price_type = '" . $typePrice . "',\n                                                            cdm_menu_discount = " . $cdm_menu_discount . ",\n                                                            cdm_updated_time = " . time() . " \n                                                            WHERE 1 \n                                                            AND cdm_desk_id = " . intval($deskID) . "\n                                                            AND cdm_menu_id = " . intval($idMenu) . "\n                                                            ");
         if ($db_update_menu_number->total >= 1) {
             $array_return['success'] = 1;
             log_action(ACTION_LOG_EDIT, 'Thêm món an (' . $idMenu . ') dã có vào bàn ID ' . $deskID);
         }
         unset($db_update_menu_number);
         echo json_encode($array_return);
     } else {
         $db_insert_current_desk_menu = new db_execute_return();
         $current_desk_menu = $db_insert_current_desk_menu->db_execute("INSERT INTO current_desk_menu \n                                                                                        (\n                                                                                        cdm_desk_id, \n                                                                                        cdm_menu_id,\n                                                                                        cdm_number,\n                                                                                        cdm_price,\n                                                                                        cdm_price_type,\n                                                                                        cdm_menu_discount,\n                                                                                        cdm_create_time,\n                                                                                        cdm_updated_time\n                                                                                        ) VALUES (\n                                                                                        " . intval($deskID) . ",\n                                                                                        " . intval($idMenu) . ",\n                                                                                        " . intval($numberMenu) . ",\n                                                                                        " . intval($men_price) . ", \n                                                                                        '" . $typePrice . "',\n                                                                                        " . $cdm_menu_discount . ", \n                                                                                        " . time() . ",\n                                                                                        " . time() . " \n                                                                                        )");
         unset($db_insert_current_desk_menu);
         // kiem tra insert da thanh cong chưa thanh cong chưa
         $db_count_current_desk_menu = new db_query("SELECT * FROM current_desk_menu \n                                                        WHERE cdm_desk_id = " . intval($deskID) . " \n                                                        ORDER BY cdm_create_time DESC \n                                                        LIMIT 1");
         if (mysqli_num_rows($db_count_current_desk_menu->result) != 0) {
             $array_return['success'] = 1;
             log_action(ACTION_LOG_ADD, 'Thêm món ăn (' . $idMenu . ') vào bàn ID ' . $deskID);
         }
         unset($db_count_current_desk_menu);
         echo json_encode($array_return);
     }
 }
コード例 #12
0
ファイル: add.php プロジェクト: nhphong0104/thietkeweb360
if ($Action =='insert')
{
	if ($module_list ==""){
		$allow_insert = 0;
		$errorMsg 			.= translate_text("Please_select_modules!");
	}
	
	//insert new user to database
	if ($allow_insert == 1){
		//Call Class generate_form();
		$querystr = $myform->generate_insert_SQL();
		$errorMsg .= $myform->checkdata();
		$last_id = 0;
		if($errorMsg == ""){
			$db_ex = new db_execute_return();
			$last_id = $db_ex->db_execute($querystr);
			unset($db_ex);
			if($last_id!=0){
				//insert user right\
				if(isset($module_list[0])){
					for ($i=0; $i< count($module_list); $i++){
						$query_str = "INSERT INTO admin_user_right VALUES(" . $last_id . "," . $module_list[$i] . ", " . getValue("adu_add" . $module_list[$i] , "int","POST") . ", " . getValue("adu_edit" . $module_list[$i] , "int","POST") . ", " . getValue("adu_delete" . $module_list[$i] , "int","POST") . ")";
						$db_ex = new db_execute($query_str);
						unset($db_ex);
					}
				}
				if(isset($user_lang_id_list[0])){
					for ($i=0; $i< count($user_lang_id_list); $i++){
						$query_str = "INSERT INTO admin_user_language VALUES(" . $last_id . "," . $user_lang_id_list[$i] .")";
						$db_ex = new db_execute($query_str);
コード例 #13
0
ファイル: ajax.php プロジェクト: virutmath/crm_local
 function importProduct()
 {
     //check quyền
     checkCustomPermission('NHAP_HANG');
     global $admin_id, $configuration;
     $array_return = array();
     //kiểm tra xem có hóa đơn nào thực hiện ko, nếu có thì exit luôn
     $db_trigger = new db_query('SELECT tri_status FROM triggers WHERE tri_key = "billSubmit" LIMIT 1');
     $trigger = mysqli_fetch_assoc($db_trigger->result);
     unset($db_trigger);
     if ($trigger['tri_status'] == 1) {
         //đang có hóa đơn được thanh toán, exit luôn
         $array_return['error'] = 'Đang có hóa đơn khác được thanh toán, bạn vui lòng thử lại trong giây lát!';
         $this->add($array_return);
         return false;
     }
     //Không có hóa đơn nào đang được xử lý - cập nhật trigger status thành 1 để bắt đầu vào hàm
     $db_update = new db_execute('UPDATE triggers SET tri_status = 1 WHERE tri_key = "billSubmit" LIMIT 1');
     unset($db_update);
     $list_product = getValue('products', 'arr', 'POST', array());
     //loại thanh toán
     $pay_type = getValue('pay_type', 'int', 'POST', 0);
     if ($pay_type !== PAY_TYPE_CASH) {
         $pay_type = PAY_TYPE_CARD;
     }
     //tính tổng tiền cần thanh toán của hóa đơn
     $bio_total_money = 0;
     foreach ($list_product as $product) {
         $bio_total_money += $product['pro_number'] * $product['pro_price'];
     }
     //insert vào bảng hóa đơn nhập hàng bill_out
     //thời gian nhập hàng
     $bio_start_time = getValue('start_date', 'int', 'POST', 0);
     //kho hàng
     $bio_store_id = getValue('store_id', 'int', 'POST', 0);
     //Trạng thái hóa đơn - ghi nợ hay đã thanh toán đủ
     $is_debit = getValue('is_debit', 'int', 'POST', 0);
     $money_debit = getValue('money_debit', 'int', 'POST', 0);
     $date_debit = getValue('date_debit', 'str', 'POST', 0, 3);
     $date_debit_convert = convertDateTime($date_debit);
     if ($is_debit) {
         if ($date_debit_convert <= time()) {
             //thời gian trả nợ không phù hợp
             $array_return['error'] = 'Thời gian hẹn trả không phù hợp!';
             $this->add($array_return);
             return false;
         }
         if ($money_debit <= 0 || $money_debit > $bio_total_money) {
             $array_return['error'] = 'Số tiền trả trước không phù hợp!';
             $this->add($array_return);
             return false;
         }
         if ($money_debit == $bio_total_money) {
             //thanh toán hết
             $is_debit = 0;
         }
     }
     //trạng thái thanh toán hóa đơn
     $bio_status = $is_debit ? BILL_STATUS_DEBIT : BILL_STATUS_SUCCESS;
     if ($bio_status == BILL_STATUS_DEBIT) {
         //gửi lên money_debit là số tiền trả trước
         //khi lưu vào bio_money_debit ta lưu số tiền còn nợ
         $bio_money_debit = $bio_total_money - $money_debit;
         $bio_date_debit = $date_debit_convert;
     } else {
         $bio_money_debit = 0;
         $bio_date_debit = 0;
     }
     //nhà cung cấp
     $bio_supplier_id = getValue('supplier', 'int', 'POST', 0);
     //check nhà cung cấp
     if (!$bio_supplier_id) {
         $array_return['error'] = 'Bạn chưa chọn nhà cung cấp!';
         $this->add($array_return);
         return false;
     }
     //ghi chú
     $bio_note = getValue('note', 'str', 'POST', '', 3);
     //người nhập hàng
     $bio_admin_id = $admin_id;
     $sql_insert = 'INSERT INTO bill_out (bio_start_time,
                                          bio_store_id,
                                          bio_status,
                                          bio_total_money,
                                          bio_supplier_id,
                                          bio_note,
                                          bio_type,
                                          bio_admin_id,
                                          bio_money_debit,
                                          bio_date_debit)
                    VALUES (
                    ' . $bio_start_time . ',
                    ' . $bio_store_id . ',
                    ' . $bio_status . ',
                    ' . $bio_total_money . ',
                    ' . $bio_supplier_id . ',
                    "' . $bio_note . '",
                    ' . $pay_type . ',
                    ' . $bio_admin_id . ',
                    ' . $bio_money_debit . ',
                    ' . $bio_date_debit . '
                    )';
     $db_insert = new db_execute_return();
     //echo $sql_insert;
     $last_id = $db_insert->db_execute($sql_insert);
     unset($db_insert);
     if (!$last_id) {
         //lỗi
         $array_return = array('error' => 'Đã có lỗi xảy ra! Vui lòng thử lại sau');
         echo json_encode($array_return);
         exit;
     }
     //sử dụng id của hóa đơn để insert vào bảng bill_out_detail
     foreach ($list_product as $product) {
         //mã hóa đơn
         $bid_bill_id = $last_id;
         //mã mặt hàng
         $bid_pro_id = $product['pro_id'];
         //số lượng
         $bid_pro_number = $product['pro_number'];
         //giá nhập
         $bid_pro_price = $product['pro_price'];
         $sql_insert = 'INSERT INTO bill_out_detail (bid_bill_id, bid_pro_id, bid_pro_number, bid_pro_price)
                        VALUES (
                        ' . $bid_bill_id . ',
                        ' . $bid_pro_id . ',
                        ' . $bid_pro_number . ',
                        ' . $bid_pro_price . '
                        )';
         $db_insert = new db_execute($sql_insert);
         unset($db_insert);
         //cộng số lượng vào kho
         //nếu không có bản ghi nào thì insert, không thì update
         $db_update = new db_execute('INSERT INTO product_quantity (product_id,store_id,pro_quantity)
                                      VALUES(' . $bid_pro_id . ',' . $bio_store_id . ',' . $bid_pro_number . ')
                                      ON DUPLICATE KEY UPDATE pro_quantity = pro_quantity + ' . $bid_pro_number);
         unset($db_update);
     }
     //insert 1 phiếu chi
     $fin_date = time();
     $fin_updated_time = time();
     //số tiền chi
     $fin_money = $bio_total_money;
     //nếu ghi nợ thì số tiền chi bằng số tiền trả trước
     if ($bio_status == BILL_STATUS_DEBIT) {
         $fin_money = $money_debit;
     }
     //lý do chi
     $fin_reason_other = 'Nhập hàng';
     //mã hóa đơn nhập hàng
     $fin_billcode = $last_id;
     //lấy thong tin nhà cung cấp
     $db_sup = new db_query('SELECT * FROM suppliers WHERE sup_id = ' . $bio_supplier_id . ' LIMIT 1');
     $supplier_data = mysqli_fetch_assoc($db_sup->result);
     unset($db_sup);
     $fin_username = $supplier_data['sup_name'];
     $fin_address = $supplier_data['sup_address'];
     $fin_cat_id = FINANCIAL_CAT_NHAP_HANG;
     $fin_pay_type = $pay_type;
     $fin_note = $bio_note;
     $fin_admin_id = $admin_id;
     $fin_agency_id = $configuration['con_default_agency'];
     //insert vào bảng financial
     $sql_insert = 'INSERT INTO financial (fin_date, fin_updated_time, fin_money, fin_reason_other, fin_billcode, fin_username, fin_address, fin_cat_id, fin_pay_type, fin_note, fin_admin_id, fin_agency_id)
                    VALUES (
                    ' . $fin_date . ',
                    ' . $fin_updated_time . ',
                    ' . $fin_money . ',
                    "' . $fin_reason_other . '",
                    "' . $fin_billcode . '",
                    "' . $fin_username . '",
                    "' . $fin_address . '",
                    ' . $fin_cat_id . ',
                    ' . $fin_pay_type . ',
                    "' . $fin_note . '",
                    ' . $fin_admin_id . ',
                    ' . $fin_agency_id . '
                    )';
     $db_insert = new db_execute_return();
     $fin_insert_id = $db_insert->db_execute($sql_insert);
     //thực hiện update trigger về 0 để giải phóng function
     $db_update = new db_execute('UPDATE triggers SET tri_status = 0 WHERE tri_key = "billSubmit" LIMIT 1');
     unset($db_update);
     if (!$fin_insert_id) {
         //lỗi
         $array_return = array('error' => 'Đã có lỗi xảy ra! Vui lòng thử lại sau');
         echo json_encode($array_return);
         exit;
     } else {
         $array_return = array('success' => 1, 'fin_id' => $fin_insert_id, 'bio_id' => $last_id);
         echo json_encode($array_return);
         exit;
     }
 }