Esempio n. 1
0
 public HttpResponseMessage RemoveRaw(double raw_id)
 {
     try
     {
         using (var context = new SAPContext())
         {
             afs_repair_raw v = new afs_repair_raw();
             v = context.afs_repair_raw.Where(t => t.REPAIR_RAW_ID == raw_id).FirstOrDefault();
             if (v != null)
             {
                 context.Entry(v).State = EntityState.Deleted;
                 context.SaveChanges();
             }
             else
             {
                 return(Request.CreateResponse(HttpStatusCode.NotFound, "Raw id is not found"));
             }
         }
         return(Request.CreateResponse(HttpStatusCode.OK));
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.InnerException.Message));
     }
 }
 public HttpResponseMessage Confirm(List <ShipmentConfirmModeal> postdata)
 {
     try
     {
         foreach (var item in postdata)
         {
             using (var context = new SAPContext())
             {
                 var shiph = context.afs_shipment_h.Where(t => t.CLIENT == item.client && t.SHIPMENT_NUMBER == item.shipment_number).FirstOrDefault();
                 if (shiph != null)
                 {
                     context.Entry(shiph).State = EntityState.Modified;
                     shiph.STATUS       = "03";
                     shiph.CONFIRM_BY   = item.confirm_by;
                     shiph.CONFIRM_DATE = DateTime.Now;
                 }
                 context.SaveChanges();
             }
         }
         return(Request.CreateResponse(HttpStatusCode.OK));
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex));
     }
 }
Esempio n. 3
0
        public HttpResponseMessage Put(afs_authority put_afs_authority)
        {
            try
            {
                using (var context = new SAPContext())
                {
                    var existing = context.afs_authority.Where(t => t.USER_ID == put_afs_authority.USER_ID).FirstOrDefault();
                    if (existing == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "afs_authority not found"));
                    }
                    else
                    {
                        context.Entry(existing).State = EntityState.Modified;
                    }

                    existing.SALE_FLAG      = put_afs_authority.SALE_FLAG;
                    existing.AFTERSALE_FLAG = put_afs_authority.AFTERSALE_FLAG;
                    existing.PURCHASE_FLAG  = put_afs_authority.PURCHASE_FLAG;
                    context.SaveChanges();

                    return(Request.CreateResponse(HttpStatusCode.OK, put_afs_authority));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
 public HttpResponseMessage removeExpense(ShipmentExpense postdata)
 {
     try
     {
         using (var context = new SAPContext())
         {
             var expense = context.afs_shipment_expense
                           .Where(t => t.CLIENT == postdata.client &&
                                  t.SHIPMENT_NUMBER == postdata.shipment_number &&
                                  t.ITEM_NO == postdata.itemno).FirstOrDefault();
             if (expense != null)
             {
                 context.Entry(expense).State = EntityState.Deleted;
                 context.SaveChanges();
             }
         }
         return(Request.CreateResponse(HttpStatusCode.OK));
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex));
     }
 }
        public HttpResponseMessage Save(ShipmentDetailModel postdata)
        {
            try
            {
                using (var context = new SAPContext())
                {
                    var            newdata    = false;
                    afs_shipment_h data       = new afs_shipment_h();
                    var            shipment_h = context.afs_shipment_h
                                                .Where(t => t.CLIENT == postdata.client && t.SHIPMENT_NUMBER == postdata.shipment_number).FirstOrDefault();
                    if (shipment_h == null)
                    {
                        newdata                    = true;
                        shipment_h                 = new afs_shipment_h();
                        shipment_h.CLIENT          = postdata.client;
                        shipment_h.SHIPMENT_NUMBER = postdata.shipment_number;
                        shipment_h.CREATED_BY      = postdata.created_by;
                        shipment_h.CREATED_DATE    = DateTime.Now;
                    }

                    shipment_h.TRANSPORT_DATE = DateTime.ParseExact(postdata.transport_date, "dd/MM/yyyy", null);
                    shipment_h.CARGROUP_CODE  = postdata.cargroup_code;
                    shipment_h.DRIVER_ID      = postdata.driver_id;
                    shipment_h.STAFF1_ID      = postdata.staff1_id;
                    shipment_h.STAFF2_ID      = postdata.staff2_id;
                    shipment_h.STATUS         = postdata.status_code;
                    shipment_h.REMARK         = postdata.remark;
                    shipment_h.POINT_ID       = postdata.point_id;
                    shipment_h.UPDATE_BY      = postdata.update_by;
                    shipment_h.UPDATE_DATE    = DateTime.Now;

                    if (newdata)
                    {
                        context.afs_shipment_h.Add(shipment_h);
                    }
                    else
                    {
                        context.Entry(shipment_h).State = EntityState.Modified;
                    }

                    // Save Shipment carries
                    if (postdata.shipment_carries != null)
                    {
                        foreach (var item in postdata.shipment_carries)
                        {
                            newdata = false;
                            var exists = context.afs_shipment_carries.Where(w =>
                                                                            w.CLIENT == item.client &&
                                                                            w.SHIPMENT_NUMBER == item.shipment_number &&
                                                                            w.ITEM_NO == item.itemno).FirstOrDefault();
                            if (exists == null)
                            {
                                newdata                = true;
                                exists                 = new afs_shipment_carries();
                                exists.CLIENT          = postdata.client;
                                exists.SHIPMENT_NUMBER = postdata.shipment_number;
                                exists.ITEM_NO         = item.itemno;
                                exists.CREATED_BY      = postdata.created_by;
                                exists.CREATED_DATE    = DateTime.Now;
                            }

                            exists.POINT_DESC       = item.point_desc;
                            exists.TIME_RANGE       = item.time_range;
                            exists.SALEORDER_NUMBER = item.so_number;
                            exists.REMARK           = item.remark;
                            exists.DRIVER_AMOUNT    = item.driver_amount;
                            exists.STAFF_AMOUNT     = item.staff_amount;
                            exists.UPDATE_BY        = postdata.update_by;
                            exists.UPDATE_DATE      = DateTime.Now;

                            if (newdata)
                            {
                                context.afs_shipment_carries.Add(exists);
                            }
                            else
                            {
                                context.Entry(exists).State = EntityState.Modified;
                            }
                        }
                    }

                    // Save Shipment expense
                    if (postdata.shipment_expense != null)
                    {
                        foreach (var item in postdata.shipment_expense)
                        {
                            newdata = false;
                            afs_shipment_expense exp = new afs_shipment_expense();
                            var exists = context.afs_shipment_expense.Where(w =>
                                                                            w.CLIENT == item.client &&
                                                                            w.SHIPMENT_NUMBER == item.shipment_number &&
                                                                            w.ITEM_NO == item.itemno
                                                                            ).FirstOrDefault();
                            if (exists == null)
                            {
                                newdata                = true;
                                exists                 = new afs_shipment_expense();
                                exists.CLIENT          = postdata.client;
                                exists.SHIPMENT_NUMBER = postdata.shipment_number;
                                exists.ITEM_NO         = item.itemno;
                                exists.EXPENSE_ID      = item.expense_id;
                                exists.CREATED_BY      = postdata.created_by;
                                exists.CREATED_DATE    = DateTime.Now;
                            }

                            exists.REMARK         = item.remark;
                            exists.EXPENSE_AMOUNT = item.expense_amount;
                            exists.UPDATE_BY      = postdata.update_by;
                            exists.UPDATE_DATE    = DateTime.Now;

                            if (newdata)
                            {
                                context.afs_shipment_expense.Add(exists);
                            }
                            else
                            {
                                context.Entry(exists).State = EntityState.Modified;
                            }
                        }
                    }

                    // Commit data
                    context.SaveChanges();

                    //Search shipment
                    ShipmentSearchModel searh  = new ShipmentSearchModel();
                    HttpResponseMessage result = new HttpResponseMessage();
                    searh.ShipmentNo = postdata.shipment_number;
                    result           = PostShipmentSearh(searh);
                    return(result);
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.InnerException.Message));
            }
        }
Esempio n. 6
0
        public HttpResponseMessage SaveAppointment(RepairForm postdata)
        {
            try
            {
                var b3gRepair = new b3gRepair();

                using (var context = new SAPContext())
                {
                    afs_repair_header h = new afs_repair_header();
                    h = context.afs_repair_header.Where(t => t.REPAIR_CODE == postdata.header.repair_code).FirstOrDefault();
                    if (h != null)
                    {
                        context.Entry(h).State = EntityState.Modified;
                    }
                    else
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Repair data not found"));
                    }

                    //set status
                    h.STATUS = postdata.header.status;
                    if (postdata.header.status != "COMPLETE")
                    {
                        if (postdata.raws.Where(w => w.status == "มีอะไหล่").Count() == postdata.raws.Count())
                        {
                            h.STATUS = "PROCESS";
                        }
                        else
                        {
                            h.STATUS = "PREPARE";
                        };
                    }
                    ;

                    h.UPDATE_BY   = postdata.header.update_by;
                    h.UPDATE_DATE = DateTime.Now;
                    context.SaveChanges();

                    //Set return value
                    postdata.header.update_by   = h.UPDATE_BY;
                    postdata.header.update_date = h.UPDATE_DATE;

                    //นัดหมายลูกค้า
                    if (postdata.appoint != null)
                    {
                        afs_repair_appointment p = new afs_repair_appointment();
                        p = context.afs_repair_appointment.Where(t => t.REPAIR_APPOINT_ID == postdata.appoint.repair_appoint_id).FirstOrDefault();
                        if (p != null)
                        {
                            context.Entry(p).State = EntityState.Modified;
                        }
                        else
                        {
                            p = new afs_repair_appointment();
                        }
                        p.APPOINTMENT_DATE = postdata.appoint.appointment_date; //DateTime.ParseExact(postdata.appoint.appointment_date, "dd/MM/yyyy", null);
                        p.APPOINTMENT_TIME = postdata.appoint.appointment_time;
                        p.TARGET_DATE      = postdata.appoint.target_date;      // DateTime.ParseExact(postdata.appoint.target_date, "dd/MM/yyyy", null);
                        p.TECHNICIAN_TEAM  = postdata.appoint.technician_team;
                        p.PRICE_AMOUNT     = postdata.appoint.price_amount;
                        p.PRICE_EXTRA      = postdata.appoint.price_extra;
                        p.REMARK_CUSTOMER  = postdata.appoint.remark_customer;
                        p.UPDATE_BY        = postdata.header.update_by;
                        p.UPDATE_DATE      = DateTime.Now;
                        if (p.REPAIR_APPOINT_ID == 0)
                        {
                            p.REPAIR_CODE  = postdata.header.repair_code;
                            p.CREATED_BY   = postdata.header.created_by;
                            p.CREATED_DATE = DateTime.Now;
                            context.afs_repair_appointment.Add(p);
                        }
                        context.SaveChanges();

                        //Set return value
                        postdata.appoint.repair_appoint_id = p.REPAIR_APPOINT_ID;
                        postdata.appoint.repair_code       = postdata.header.repair_code;
                    }

                    List <afs_repair_raw> i = new List <afs_repair_raw>();
                    foreach (var item in postdata.raws)
                    {
                        afs_repair_raw v = new afs_repair_raw();
                        v = context.afs_repair_raw.Where(t => t.REPAIR_RAW_ID == item.repair_raw_id).FirstOrDefault();
                        if (v != null)
                        {
                            context.Entry(v).State = EntityState.Modified;
                        }
                        else
                        {
                            v = new afs_repair_raw();
                        }
                        v.RAW_NAME = item.raw_name;
                        v.RAW_QTY  = item.raw_qty;
                        v.STATUS   = item.status;
                        if (item.raw_date.HasValue)
                        {
                            v.RAW_DATE = item.raw_date.Value; //DateTime.ParseExact(item.raw_date, "dd/MM/yyyy", null);
                        }
                        ;
                        v.REMARK      = item.remark;
                        v.UPDATE_BY   = postdata.header.update_by;
                        v.UPDATE_DATE = DateTime.Now;

                        if (item.repair_raw_id == 0)
                        {
                            v.REPAIR_CODE  = postdata.header.repair_code;
                            v.CREATED_BY   = postdata.header.created_by;
                            v.CREATED_DATE = DateTime.Now;
                            context.afs_repair_raw.Add(v);
                        }
                        context.SaveChanges();

                        //Set return value
                        item.repair_raw_id = v.REPAIR_RAW_ID;
                        item.repair_code   = postdata.header.repair_code;
                    }
                    ;
                }

                return(Request.CreateResponse(HttpStatusCode.OK, postdata));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.InnerException.Message));
            }
        }
Esempio n. 7
0
        public HttpResponseMessage Save(RepairForm postdata)
        {
            try
            {
                var b3gRepair = new b3gRepair();

                using (var context = new SAPContext())
                {
                    afs_repair_header h = new afs_repair_header();
                    h = context.afs_repair_header.Where(t => t.REPAIR_CODE == postdata.header.repair_code).FirstOrDefault();
                    if (h != null)
                    {
                        context.Entry(h).State = EntityState.Modified;
                    }
                    else
                    {
                        h = new afs_repair_header();
                    }
                    h.TRANSPORT_AMOUNT = postdata.header.transport_amount;
                    h.CONTACT_TEL      = postdata.header.contact_tel;
                    h.REMARK           = postdata.header.remark;
                    h.STATUS           = postdata.header.status;
                    h.UPDATE_BY        = postdata.header.update_by;
                    h.UPDATE_DATE      = DateTime.Now;
                    if (string.IsNullOrEmpty(h.REPAIR_CODE))
                    {
                        h.REPAIR_CODE  = b3gRepair.GetNextDocumentNumber();
                        h.REPAIR_DATE  = DateTime.Now;
                        h.SO_NUMBER    = postdata.header.so_number;
                        h.SOLDTO_CODE  = postdata.header.soldto_code;
                        h.SOLDTO_NAME  = postdata.header.soldto_name;
                        h.CREATED_BY   = postdata.header.created_by;
                        h.CREATED_DATE = DateTime.Now;
                        context.afs_repair_header.Add(h);
                    }
                    context.SaveChanges();

                    //Set return value
                    postdata.header.repair_code  = h.REPAIR_CODE;
                    postdata.header.repair_date  = h.REPAIR_DATE;
                    postdata.header.created_by   = h.CREATED_BY;
                    postdata.header.created_date = h.CREATED_DATE;
                    postdata.header.update_by    = h.UPDATE_BY;
                    postdata.header.update_date  = h.UPDATE_DATE;

                    List <afs_repair_items> i = new List <afs_repair_items>();
                    foreach (var item in postdata.items)
                    {
                        afs_repair_items v = new afs_repair_items();
                        v = context.afs_repair_items.Where(t => t.REPAIR_ITEM_ID == item.repair_item_id).FirstOrDefault();
                        if (v != null)
                        {
                            context.Entry(v).State = EntityState.Modified;
                        }
                        else
                        {
                            v = new afs_repair_items();
                        }
                        v.REPAIR_ITEM_TYPE = item.repair_item_type;
                        v.REPAIR_QTY       = item.qty;
                        v.REPAIR_REMARK    = item.repair_remark;
                        v.REPAIR_DESC      = item.repair_desc;
                        v.REPAIR_TYPE      = item.repair_type;
                        v.WARANTY          = item.waranty;
                        v.UPDATE_BY        = postdata.header.update_by;
                        v.UPDATE_DATE      = DateTime.Now;

                        if (item.repair_item_id == 0)
                        {
                            v.REPAIR_CODE  = h.REPAIR_CODE;
                            v.SO_NUMBER    = item.so_number;
                            v.SO_ITEM      = item.so_item;
                            v.CREATED_BY   = postdata.header.created_by;
                            v.CREATED_DATE = DateTime.Now;
                            context.afs_repair_items.Add(v);
                        }
                        context.SaveChanges();

                        //Set return value
                        item.select         = true;
                        item.repair_item_id = v.REPAIR_ITEM_ID;
                        item.repair_code    = v.REPAIR_CODE;

                        if (item.images != null)
                        {
                            List <afs_repair_images> m = new List <afs_repair_images>();
                            foreach (var img in item.images)
                            {
                                afs_repair_images im = new afs_repair_images();
                                im = context.afs_repair_images.Where(t => t.REPAIR_IMAGE_ID == img.repair_image_id).FirstOrDefault();
                                if (im != null)
                                {
                                    context.Entry(im).State = EntityState.Modified;
                                }
                                else
                                {
                                    im = new afs_repair_images();
                                }
                                im.FILENAME = img.filename;
                                im.BASE64   = img.base64;
                                if (img.repair_image_id == 0)
                                {
                                    im.REPAIR_CODE    = h.REPAIR_CODE;
                                    im.REPAIR_ITEM_ID = v.REPAIR_ITEM_ID;
                                    im.SO_NUMBER      = item.so_number;
                                    im.SO_ITEM        = item.so_item;
                                    context.afs_repair_images.Add(im);
                                }
                                context.SaveChanges();

                                //Set return value
                                img.repair_image_id = im.REPAIR_IMAGE_ID;
                                img.repair_code     = im.REPAIR_CODE;
                                img.repair_item_id  = im.REPAIR_ITEM_ID;
                            }
                        }
                    }
                    ;
                }

                return(Request.CreateResponse(HttpStatusCode.OK, postdata));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }