Programmer:Purchase Order v2

From AutoCount Resource Center
Jump to navigation Jump to search

Technical Specification

  1. NetTotal must not be negative amount
  2. Document NetTotal amount is read-only, as the net total must be the sum of detail total (sub-total).

Assemblies version 2.0

AutoCount.Accounting.dll
AutoCount.Accounting.UI.dll
AutoCount.dll
AutoCount.MainEntry.dll
AutoCount.UI.dll
AutoCount.Invoicing.dll
AutoCount.Invoicing.Purchase.dll

New

public void NewPurchaseOrder(AutoCount.Authentication.UserSession userSession)
{
    string docNo = "PO-0001";

    AutoCount.Invoicing.Purchase.PurchaseOrder.PurchaseOrderCommand cmd =
        AutoCount.Invoicing.Purchase.PurchaseOrder.PurchaseOrderCommand.Create(userSession, userSession.DBSetting);
    AutoCount.Invoicing.Purchase.PurchaseOrder.PurchaseOrder doc = cmd.AddNew();
    AutoCount.Invoicing.Purchase.PurchaseOrder.PurchaseOrderDetail dtl;

    doc.DocNo = docNo; //PO number
    doc.DocDate = DateTime.Today.Date;

    //PO Item (Line/Detail)
    for (int i=0; i<3; i++)
    {
        dtl = doc.AddDetail();
        dtl.ItemCode = "FG00001";
        dtl.UOM = "UNIT";
        dtl.Location = "HQ";
        dtl.Qty = 1M;
        dtl.UnitPrice = 10.50M;
        dtl.EstimatedDeliveryDate = "";
        dtl.DeliveryDate = DateTime.Today.Add(new TimeSpan(3)).Date;
    }

    try
    {
        doc.Save();
        //Log success
        AutoCount.AppMessage.ShowMessage(
            string.Format("Successful saved P/O: {0}", doc.DocNo));
    }
    catch (AutoCount.AppException ex)
    {
        //Log failed
    }
}

New or Update

public void NewUpdatePurchaseOrder(AutoCount.Authentication.UserSession userSession)
{
    string docNo = "PO-0001";

    AutoCount.Invoicing.Purchase.PurchaseOrder.PurchaseOrderCommand cmd =
        AutoCount.Invoicing.Purchase.PurchaseOrder.PurchaseOrderCommand.Create(userSession, userSession.DBSetting);
    AutoCount.Invoicing.Purchase.PurchaseOrder.PurchaseOrder doc = cmd.Edit(docNo);
    AutoCount.Invoicing.Purchase.PurchaseOrder.PurchaseOrderDetail dtl;

    if (doc == null)
    {
        NewPurchaseOrder(userSession);
        return;
    }

    doc.DocDate = DateTime.Today.Date;

    //PO Item (Line/Detail)
    for (int i = 0; i < 3; i++)
    {
        dtl = doc.AddDetail();
        dtl.ItemCode = "FG00002";
        dtl.UOM = "UNIT";
        dtl.Location = "HQ";
        dtl.Qty = 1M;
        dtl.UnitPrice = 10.50M;
        dtl.EstimatedDeliveryDate = "";
        dtl.DeliveryDate = DateTime.Today.Add(new TimeSpan(3)).Date;
    }

    try
    {
        doc.Save();
        //Log success
        AutoCount.AppMessage.ShowMessage(
            string.Format("Successful update P/O: {0}", doc.DocNo));
    }
    catch (AutoCount.AppException ex)
    {
        //Log failed
    }
}

Cancel

public void CancelPurchaseOrder(AutoCount.Authentication.UserSession userSession)
{
    string docNo = "PO-0001";

    AutoCount.Invoicing.Purchase.PurchaseOrder.PurchaseOrderCommand cmd =
        AutoCount.Invoicing.Purchase.PurchaseOrder.PurchaseOrderCommand.Create(userSession, userSession.DBSetting);

    if (cmd.CancelDocument(docNo, userSession.LoginUserID))
    {
        //Log success
        AutoCount.AppMessage.ShowMessage(
            string.Format("{0} is cancelled.", docNo));
    }
    else
    {
        //Log failed
        AutoCount.AppMessage.ShowMessage(
            string.Format("Failed to cancel {0}.", docNo));
    }
}

Delete

public void DeletePurchaseOrder(AutoCount.Authentication.UserSession userSession)
{
    string docNo = "PO-0001";

    AutoCount.Invoicing.Purchase.PurchaseOrder.PurchaseOrderCommand cmd =
        AutoCount.Invoicing.Purchase.PurchaseOrder.PurchaseOrderCommand.Create(userSession, userSession.DBSetting);

    try
    {
        cmd.Delete(docNo);
        //Log success
        AutoCount.AppMessage.ShowMessage(
            string.Format("{0} is deleted.", docNo));
    }
    catch (Exception)
    {
        //Log failed
        AutoCount.AppMessage.ShowMessage(
            string.Format("Failed to delete {0}.", docNo));
    }
}


See Also

Go to menu

IconAC81.png Go to top
ProgrammerGo.jpg Resources For AutoCount Software Developers