public string CheckThongTinKhachHang(Add_Bill item)
        {
            string rs = null;

            if (string.IsNullOrEmpty(item.tenkh))
            {
                return(rs = "Tên khách hàng không được để trống");
            }
            if (string.IsNullOrEmpty(item.dienthoai))
            {
                return(rs = "SĐT khách hàng không được để trống");
            }

            var checkKH =
                db.service_customer.FirstOrDefault(m => m.fullname == item.tenkh && m.mobile == item.dienthoai);

            if (checkKH == null)
            {
                service_customer inew = new service_customer();
                inew.fullname    = item.tenkh;
                inew.mobile      = item.dienthoai;
                inew.address     = item.diachi;
                inew.id_center   = item.id_center;
                inew.code_center = item.code_center;
                inew.created_at  = DateTime.Now;
                inew.created_by  = item.tennguoithaotac;
                inew.status      = 1;
                inew.note        = "Thêm mới khách hàng khi bán đại lý";
                db.service_customer.Add(inew);
                db.SaveChanges();
            }

            return(null);
        }
示例#2
0
        public ActionResult _xuat_ban_daily(FormCollection formCollection)
        {
            // kiểm tra quyền thêm sửa
            var sys = CheckActiveMenu.ReturnActive(SystemMessageConst.TypeAction.Addnew);

            if (sys.IsSuccess == false)
            {
                return(Json(new { result = sys }, JsonRequestBehavior.AllowGet));
            }

            Add_Bill item = new Add_Bill();

            item.type     = "DL";
            item.loaibill = 1;
            item.data     = formCollection.Get("data");

            item.billType   = formCollection.Get("billType");
            item.bonusTotal = long.Parse(formCollection.Get("bonusTotal"));
            item.total      = long.Parse(formCollection.Get("total"));
            item.discount   = long.Parse(formCollection.Get("discount"));

            item.billNumber = formCollection.Get("billNumber");
            item.ngayxuat   = formCollection.Get("ngayxuat");
            item.nguoixuat  = formCollection.Get("nguoixuat");
            item.notebill   = formCollection.Get("notebill");

            item.tenkh        = formCollection.Get("tenkh");
            item.diachi       = formCollection.Get("diachi");
            item.nguoidaidien = formCollection.Get("nguoidaidien");
            item.dienthoai    = formCollection.Get("dienthoai");

            item.id_center       = user.BranchId;
            item.id_thaotac      = user.Id;
            item.code_center     = user.Code_brand;
            item.tennguoithaotac = user.FullName;

            var db = new xuat_dailyBusiness();

            var result = db.AddBillProduct(item);

            // luu log - thêm mới
            CheckRuleAndSaveLog.ReturnCheckRuleAndSaveLog(DbLogType.Create.ToString(), result.IsSuccess, JsonConvert.SerializeObject(new { data = item }, Newtonsoft.Json.Formatting.Indented, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            }));


            return(Json(new { result }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Xoadonhang(int id_bill)
        {
            var db = new danhsachphieuxuatBusiness();

            var result = db.BS_Huydonhang(id_bill, user.FullName);

            Add_Bill item = new Add_Bill();

            item.id_center       = user.BranchId;
            item.id_thaotac      = user.Id;
            item.code_center     = user.Code_brand;
            item.tennguoithaotac = user.FullName;
            item.id_bill         = id_bill;
            item.data            = "Hủy đơn hàng";

            // luu log - thêm mới
            CheckRuleAndSaveLog.ReturnCheckRuleAndSaveLog(DbLogType.Create.ToString(), result.IsSuccess, JsonConvert.SerializeObject(new { data = item }, Newtonsoft.Json.Formatting.Indented, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            }));

            return(Json(new { result }, JsonRequestBehavior.AllowGet));
        }
示例#4
0
        // _Dell_Bill_Detail ham dung chung trong  file banhang.js
        public ActionResult _Dell_Bill_Detail(FormCollection formCollection)
        {
            int id_bill_detail = int.Parse(formCollection.Get("id_bill_dt"));
            var db             = new xuat_dailyBusiness();

            var result = db.Xoasanphamkhoidonhang(id_bill_detail);

            Add_Bill item = new Add_Bill();

            item.id_center       = user.BranchId;
            item.id_thaotac      = user.Id;
            item.code_center     = user.Code_brand;
            item.tennguoithaotac = user.FullName;
            item.id_bill_detail  = id_bill_detail;
            item.data            = "Xóa sản phẩm khỏi bill";

            // luu log - thêm mới
            CheckRuleAndSaveLog.ReturnCheckRuleAndSaveLog(DbLogType.Create.ToString(), result.IsSuccess, JsonConvert.SerializeObject(new { data = item }, Newtonsoft.Json.Formatting.Indented, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            }));

            return(Json(new { result }, JsonRequestBehavior.AllowGet));
        }
        public SystemMessage EditBillProduct(Add_Bill item_bill)
        {
            SystemMessage systemMessage = new SystemMessage();

            try
            {
                var checkBillInvail = db.service_customer_bill.FirstOrDefault(m => m.id == item_bill.id_bill);
                if (checkBillInvail == null)
                {
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = "Không tìm thấy đơn hàng";
                    return(systemMessage);
                }

                var checkkh = CheckThongTinKhachHang(item_bill);
                if (checkkh != null)
                {
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = checkkh;
                    return(systemMessage);
                }

                var TTKH = db.service_customer.FirstOrDefault(m => m.mobile == item_bill.dienthoai && m.fullname == item_bill.tenkh && m.id_center == item_bill.id_center);

                if (TTKH == null)
                {
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = "Thông tin khách hàng không tồn tại";
                    return(systemMessage);
                }

                //var check = ValidateAddBillProduct(item_bill.data);
                //if (check != null)
                //{
                //    systemMessage.IsSuccess = false;
                //    systemMessage.Message = check;
                //    return systemMessage;
                //}

                var checkTypeBill = db.sys_parameter.FirstOrDefault(ob =>
                                                                    ob.code == SystemMessageConst.Key.StatusBillForm && ob.value == item_bill.billType);
                if (checkTypeBill == null)
                {
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = "Không tồn tại hình thức thanh toán !";
                    return(systemMessage);
                }


                var arrData = item_bill.data.Split(',');
                //if (arrData.Length == 0)
                //{
                //    systemMessage.IsSuccess = false;
                //    systemMessage.Message = "Bạn chưa chọn sản phẩm !";
                //    return systemMessage;
                //}

                var checkNumber =
                    db.service_customer_bill.FirstOrDefault(
                        ob => ob.code == item_bill.billNumber && ob.id != item_bill.id_bill);
                if (checkNumber != null)
                {
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = "Số hóa đơn đã tồn tại !";
                    return(systemMessage);
                }

                // TAO BILL
                //    checkBillInvail.type = "DL";
                //    checkBillInvail.billtype = 1;
                checkBillInvail.id_customer  = TTKH.id;
                checkBillInvail.tenKH        = TTKH.fullname;
                checkBillInvail.tongtien     = item_bill.total;
                checkBillInvail.giamgia      = item_bill.bonusTotal;
                checkBillInvail.thucnhan     = item_bill.discount;
                checkBillInvail.method       = item_bill.billType;
                checkBillInvail.ispay        = 0; //chưa thanh toán
                checkBillInvail.updated_at   = DateTime.Now;
                checkBillInvail.updated_by   = item_bill.tennguoithaotac;
                checkBillInvail.deleted      = 0;
                checkBillInvail.status       = 0;
                checkBillInvail.date_sale    = DateTime.Now;
                checkBillInvail.id_center    = item_bill.id_center;
                checkBillInvail.tennguoixuat = item_bill.nguoixuat;
                checkBillInvail.code         = item_bill.billNumber;

                var lstProduct = db.sys_product.ToList();

                foreach (var item in arrData)
                {
                    if (item.Contains("*"))
                    {
                        var productInfo = item.Split('*');

                        int    id_product         = 0;
                        int    quantity           = 0;
                        long   price              = 0;
                        string group_code_product = "";
                        int    id_unit            = 0;
                        string unit_name          = "";



                        Int32.TryParse(productInfo[0], out id_product);
                        Int32.TryParse(productInfo[1], out quantity);
                        long.TryParse(productInfo[2], out price);
                        group_code_product = productInfo[3];
                        Int32.TryParse(productInfo[4], out id_unit);
                        unit_name = productInfo[5];

                        if (quantity < 1)
                        {
                            systemMessage.IsSuccess = false;
                            systemMessage.Message   = "Số lượng sản phẩm không hợp lệ";
                            return(systemMessage);
                        }

                        var checkProduct = lstProduct.FirstOrDefault(ob => ob.id == id_product);
                        if (checkProduct == null)
                        {
                            systemMessage.IsSuccess = false;
                            systemMessage.Message   = "Sản phẩm không tồn tại ";
                            return(systemMessage);
                        }


                        var checktrung = db.service_customer_bill_detail.FirstOrDefault(m =>
                                                                                        m.id_product == id_product && m.groupcodeproduct == group_code_product &&
                                                                                        m.id_bill == item_bill.id_bill);

                        int new_id_bill_detail = 0;


                        if (checktrung == null)
                        {
                            service_customer_bill_detail serviceCustomerBillDetail = new service_customer_bill_detail();

                            serviceCustomerBillDetail.id_bill          = item_bill.id_bill;
                            serviceCustomerBillDetail.id_product       = id_product;
                            serviceCustomerBillDetail.price            = price;
                            serviceCustomerBillDetail.quantity         = quantity;
                            serviceCustomerBillDetail.unit             = id_unit;
                            serviceCustomerBillDetail.unit_name        = unit_name;
                            serviceCustomerBillDetail.status           = 0;
                            serviceCustomerBillDetail.create_at        = DateTime.Now;
                            serviceCustomerBillDetail.product_name     = checkProduct.name;
                            serviceCustomerBillDetail.groupcodeproduct = group_code_product;

                            db.service_customer_bill_detail.Add(serviceCustomerBillDetail);
                            new_id_bill_detail = serviceCustomerBillDetail.id;
                            db.SaveChanges();
                        }
                        else
                        {
                            int sl = 0;
                            sl = checktrung.quantity.Value;

                            checktrung.quantity = sl + quantity;
                            new_id_bill_detail  = checktrung.id;
                        }



                        // tru ton kho

                        var checkTonkho = db.sys_tonkho.Where(m =>
                                                              m.id_product == id_product && m.id_center == item_bill.id_center && m.isactive == true).FirstOrDefault();

                        if (checkTonkho == null)
                        {
                            systemMessage.IsSuccess = false;
                            systemMessage.Message   = "Sản phẩm không tồn tại trong kho !!";
                            return(systemMessage);
                        }

                        if (checkTonkho.soluong == 0)
                        {
                            systemMessage.IsSuccess = false;
                            systemMessage.Message   = "Sản phẩm đã hết, không thể tạo phiếu xuất !!";
                            return(systemMessage);
                        }

                        if (checkTonkho.soluong < quantity)
                        {
                            systemMessage.IsSuccess = false;
                            systemMessage.Message   = "Số lượng xuất nhiều hơn số lượng tồn !!";
                            return(systemMessage);
                        }

                        int sl_ton = 0;
                        sl_ton = checkTonkho.soluong;
                        checkTonkho.soluong = sl_ton - quantity;

                        // đổi trang thai từng sp
                        var lstCodeProduct = db.sys_code_product.Where(m =>
                                                                       m.group_code == group_code_product && m.id_product == id_product &&
                                                                       m.id_center == item_bill.id_center && m.trangthai == 0).ToList();

                        if (lstCodeProduct.Count == 0)
                        {
                            systemMessage.IsSuccess = false;
                            systemMessage.Message   = "Dữ liệu nhớm sản phẩm không tồn tại";
                            return(systemMessage);
                        }
                        if (lstCodeProduct.Count < quantity)
                        {
                            systemMessage.IsSuccess = false;
                            systemMessage.Message   = "Số lượng nhóm sản phẩm còn lại không hợp lệ";
                            return(systemMessage);
                        }

                        for (int i = 0; i < quantity; i++)
                        {
                            lstCodeProduct[i].ngayxuat   = DateTime.Now;
                            lstCodeProduct[i].nguoixuat  = item_bill.nguoixuat;
                            lstCodeProduct[i].tenKH      = item_bill.tenkh;
                            lstCodeProduct[i].trangthai  = 1;
                            lstCodeProduct[i].id_bill_dt = new_id_bill_detail;
                        }
                    }
                }

                db.SaveChanges();
                systemMessage.id_bill   = item_bill.id_bill;
                systemMessage.IsSuccess = true;
                systemMessage.Message   = SystemMessageConst.systemmessage.UpdateSuccess;
                return(systemMessage);
            }
            catch (Exception e)
            {
                systemMessage.IsSuccess = false;
                systemMessage.Message   = e.ToString();
                return(systemMessage);
            }
        }