Programmer:Cash Sale with Payment: Difference between revisions

mNo edit summary
 
(16 intermediate revisions by the same user not shown)
Line 1:
==Technical Specification==
{{NavigateDeveloper}}
===Rules in Sale Cash Sale===
# NetTotal must not be negative amount
# Negative Quantity is allowed, if it does not violate the NetTotal rule.
 
==Columns Specification==
===Assemblies version 1.8===
===Master Table===
<pre>
{| class="wikitable mw-collapsible mw-collapsed"
BCE.AutoCount.Invoicing.dll
!colspan=5|Columns Table
BCE.AutoCount.Invoicing.Sales.dll
|-
</pre>
! Column Name !! Data Type !! Size !! Mandatory !! Remark
|-
| DocNo || string || 20 || Yes || If apply system running number,<br/>do not assign or assign "<<New>>"
|-
| DocDate || DateTime || || Yes || '''Date only, without time'''<br/>Eg. DateTime.Today.Date
|-
| DebtorCode || string || 12 || Yes ||
|-
| Description || string || 100 || No ||
|-
| RefDocNo || string || 20 || No ||
|-
| Remark1 || string || 40 || No ||
|-
| Remark2 || string || 40 || No ||
|-
| Remark3 || string || 40 || No ||
|-
| Remark4 || string || 40 || No ||
|-
| Note || string || Max || No ||
|}
 
===CreateDetail New Cash SaleTable===
{| class="wikitable mw-collapsible mw-collapsed"
!colspan=5|Columns Table
|-
! Column Name !! Data Type !! Size !! Mandatory !! Remark
|-
| ItemCode || string || 30 || No || Value must be maintained at Stock > [[Programmer:Stock Item|Item Maintenance]]
|-
| Location || string || 8 || No || Value must be maintained at Stock > Stock Location Maintenance
|-
| BatchNo || string || 20 || No || Value must be maintained at Stock > [[Programmer:Stock Item|Item Maintenance]] > Item Batch<br/>Requires enable "Item Batch No." module,<br/>and Item is controlled by BatchNo.<br/>Default: DBNull.Value
|-
| Description || string || 100 || No ||
|-
| FurtherDescription || string || Max || No ||
|}
 
===ClassesPayment of sourceTable===
{| class="wikitable mw-collapsible mw-collapsed"
!colspan=5|Columns Table
|-
! Column Name !! Data Type !! Size !! Mandatory !! Remark
|-
| PaymentMethod || string || 20 || No || Value must be maintained in General Maintenance -> Payment Method Maintenance.
|-
| PaymentBy || string || 20 || No ||
|-
| ChequeNo || string || 20 || No ||
|-
| PaymentAmt || decimal || 18,4 || Yes ||
|}
 
==References of AutoCount Accounting version 1.8, 1.9==
{{BaseReferenceAC18}}
'''BCE.AutoCount.Invoicing.dll'''
'''BCE.AutoCount.Invoicing.Sales.dll'''
 
==Cash Sale API Usage==
===New===
<syntaxhighlight lang="csharp">
public void NewCashSale(BCE.Data.DBSetting dbSetting)
{
BCE.AutoCount.Invoicing.Sales.CashSale.CashSaleCommand cmd =
BCE.AutoCount.Invoicing.Sales.CashSale.CashSaleCommand.Create(dbSetting);
BCE.AutoCount.Invoicing.Sales.CashSale.CashSale doc = cmd.AddNew();
BCE.AutoCount.Invoicing.Sales.CashSale.CashSaleDetail dtl;
 
doc.DebtorCode = "300-C001";
doc.DocNo = "CS-00011";
doc.DocDate = DateTime.Today.Date;
 
dtl = doc.AddDetail();
dtl.ItemCode = "FG00001";
dtl.Qty = 1;
dtl.UOM = "UNIT";
dtl.UnitPrice = 50.20M;
 
dtl = doc.AddDetail();
dtl.ItemCode = "FG00002";
dtl.Qty = 10;
dtl.UOM = "UNIT";
dtl.UnitPrice = 60.20M;
dtl.Discount = "30%";
 
doc.Save();
}
</syntaxhighlight>
 
===ImplementationEdit===
<syntaxhighlight lang="csharp">
public void EditCashSale(BCE.Data.DBSetting dbSetting)
{
BCE.AutoCount.Invoicing.Sales.CashSale.CashSaleCommand cmd =
BCE.AutoCount.Invoicing.Sales.CashSale.CashSaleCommand.Create(dbSetting);
BCE.AutoCount.Invoicing.Sales.CashSale.CashSale doc = cmd.Edit("CS-00011");
BCE.AutoCount.Invoicing.Sales.CashSale.CashSaleDetail dtl;
 
if (doc != null)
{
doc.ClearDetails();
dtl = doc.AddDetail();
dtl.ItemCode = "FG00001";
dtl.Qty = 1;
dtl.UOM = "UNIT";
dtl.UnitPrice = 50.20M;
 
dtl = doc.AddDetail();
dtl.ItemCode = "FG00003";
dtl.Qty = 10;
dtl.UOM = "UNIT";
dtl.UnitPrice = 6.30M;
dtl.Discount = "30%";
 
doc.Save();
==See Also==
}
* [[Programmer:Quotation]]
}
* [[Programmer:Sales Order]]
</syntaxhighlight>
* [[Programmer:Delivery Order]]
* [[Programmer:Sales Invoice]]
* [[Programmer:Cash Sale with Payment]]
 
===Cancel===
[[Category:Programmer]]
<syntaxhighlight lang="csharp">
[[Category:API]]
public void CancelCashSale(BCE.Data.DBSetting dbSetting)
[[Category:Integrate]]
{
[[Category:Plug-In]]
BCE.AutoCount.Invoicing.Sales.CashSale.CashSaleCommand cmd =
BCE.AutoCount.Invoicing.Sales.CashSale.CashSaleCommand.Create(dbSetting);
 
cmd.CancelDocument("CS-00011", BCE.AutoCount.Authentication
.UserAuthentication.GetOrCreate(dbSetting).LoginUserID);
}
</syntaxhighlight>
 
===Delete===
<syntaxhighlight lang="csharp">
public void DeleteCashSale(BCE.Data.DBSetting dbSetting)
{
BCE.AutoCount.Invoicing.Sales.CashSale.CashSaleCommand cmd =
BCE.AutoCount.Invoicing.Sales.CashSale.CashSaleCommand.Create(dbSetting);
 
cmd.Delete("CS-00011");
}
</syntaxhighlight>
 
<br/>
==New Cash Sale with Payments==
<tabber>
1. CASH=
<syntaxhighlight lang="c#">
public void NewCashSaleWithCash(BCE.Data.DBSetting dbSetting)
{
BCE.AutoCount.Invoicing.Sales.CashSale.CashSaleCommand cmd =
BCE.AutoCount.Invoicing.Sales.CashSale.CashSaleCommand.Create(dbSetting);
BCE.AutoCount.Invoicing.Sales.CashSale.CashSale doc = cmd.AddNew();
BCE.AutoCount.Invoicing.Sales.CashSale.CashSaleDetail dtl;
 
//doc.DocNo = "CS-00011";
doc.DebtorCode = "300-C001";
doc.DocDate = DateTime.Today.Date;
 
//Enable 5 cents rounding in this document
//Ensure the "5 Cents Rounding Adjustment Account" is set to an account,
//in Tools | Options > G/L | G/L Posting...
doc.IsRoundAdj = true;
 
dtl = doc.AddDetail();
dtl.ItemCode = "FG00001";
dtl.Qty = 1;
dtl.UOM = "UNIT";
dtl.UnitPrice = 50.20M;
dtl.TaxType = "S-10";
 
dtl = doc.AddDetail();
dtl.ItemCode = "FG00002";
dtl.Qty = 10;
dtl.UOM = "UNIT";
dtl.UnitPrice = 60.20M;
dtl.Discount = "30%";
dtl.TaxType = "S-10";
 
//FinalTotal is the total after 5 cents rounding
MakeCashPayment(doc, doc.FinalTotal, dbSetting);
 
try
{
doc.Save();
BCE.Application.AppMessage.ShowMessage($"{doc.DocNo} is created.");
}
catch (Exception ex)
{
BCE.Application.AppMessage.ShowErrorMessage($"Failed to save Cash Sale.\n{ex.Message}");
}
}
 
//Create a Cash Payment for a Cash Sale
private void MakeCashPayment(BCE.AutoCount.Invoicing.Sales.CashSale.CashSale cs, decimal cashAmt, BCE.Data.DBSetting dbSetting)
{
//PaymentMode 1 indicate the payment in this Cash Sale is by Cash
cs.PaymentMode = 1;
 
cs.CashPayment = cashAmt;
cs.CCApprovalCode = DBNull.Value;
cs.CashSalePayment.ARPayment.ClearDetails();
 
cs.CashSalePayment = BCE.AutoCount.Invoicing.Sales.SalesPayment.Create(
cs.ReferPaymentDocKey, cs.DocKey,
BCE.AutoCount.Document.DocumentType.CashSale, dbSetting);
 
cs.CashSalePayment.DebtorCode = cs.DebtorCode;
cs.CashSalePayment.CurrencyCode = cs.CurrencyCode;
cs.CashSalePayment.DocDate = cs.DocDate;
 
BCE.AutoCount.ARAP.ARPayment.ARPaymentDTLEntity payDtl = cs.CashSalePayment.ARPayment.NewDetail();
 
//"CASH" must be maintained
//in General Maintenance | Payment Method Maintenance
payDtl.PaymentMethod = "CASH";
payDtl.PaymentAmt = cashAmt;
 
if (cs.CashSalePayment.PaymentAmt > 0)
cs.ReferPaymentDocKey = cs.CashSalePayment.DocKey;
}
</syntaxhighlight>
|-|
2. Credit Card=
<syntaxhighlight lang="c#">
public void NewCashSaleWithCreditCard(BCE.Data.DBSetting dbSetting)
{
BCE.AutoCount.Invoicing.Sales.CashSale.CashSaleCommand cmd =
BCE.AutoCount.Invoicing.Sales.CashSale.CashSaleCommand.Create(dbSetting);
BCE.AutoCount.Invoicing.Sales.CashSale.CashSale doc = cmd.AddNew();
BCE.AutoCount.Invoicing.Sales.CashSale.CashSaleDetail dtl;
 
//doc.DocNo = "CS-00011";
doc.DebtorCode = "300-C001";
doc.DocDate = DateTime.Today.Date;
 
//Enable 5 cents rounding in this document
//Ensure the "5 Cents Rounding Adjustment Account" is set to an account,
//in Tools | Options > G/L | G/L Posting...
doc.IsRoundAdj = true;
 
dtl = doc.AddDetail();
dtl.ItemCode = "FG00001";
dtl.Qty = 1;
dtl.UOM = "UNIT";
dtl.UnitPrice = 50.20M;
dtl.TaxType = "S-10";
 
dtl = doc.AddDetail();
dtl.ItemCode = "FG00002";
dtl.Qty = 10;
dtl.UOM = "UNIT";
dtl.UnitPrice = 60.20M;
dtl.Discount = "30%";
dtl.TaxType = "S-10";
 
MakeCreditCardPayment(doc, doc.FinalTotal, dbSetting);
 
try
{
doc.Save();
BCE.Application.AppMessage.ShowMessage($"{doc.DocNo} is created.");
}
catch (Exception ex)
{
BCE.Application.AppMessage.ShowErrorMessage($"Failed to save Cash Sale.\n{ex.Message}");
}
}
 
private void MakeCreditCardPayment(BCE.AutoCount.Invoicing.Sales.CashSale.CashSale cs, decimal cardAmt, BCE.Data.DBSetting dbSetting)
{
//PaymentMode 2 indicate the payment with Card
//or similar payment mode that requires "Approval Code" and "Card No".
cs.PaymentMode = 2;
cs.CashPayment = 0M;
cs.CCApprovalCode = "ABC0100123";
cs.CashSalePayment.ARPayment.ClearDetails();
 
cs.CashSalePayment = BCE.AutoCount.Invoicing.Sales.SalesPayment.Create(
cs.ReferPaymentDocKey, cs.DocKey,
BCE.AutoCount.Document.DocumentType.CashSale, dbSetting);
 
cs.CashSalePayment.DebtorCode = cs.DebtorCode;
cs.CashSalePayment.CurrencyCode = cs.CurrencyCode;
cs.CashSalePayment.DocDate = cs.DocDate;
 
BCE.AutoCount.ARAP.ARPayment.ARPaymentDTLEntity payDtl = cs.CashSalePayment.ARPayment.NewDetail();
 
//"MASTER" must be maintained
//in General Maintenance | Payment Method Maintenance
payDtl.PaymentMethod = "MASTER";
payDtl.ChequeNo = "12XXXX-YYY-ZZZ-1234";
payDtl.PaymentAmt = cardAmt;
 
if (cs.CashSalePayment.PaymentAmt > 0)
cs.ReferPaymentDocKey = cs.CashSalePayment.DocKey;
}
</syntaxhighlight>
|-|
3. Multi Payment=
<syntaxhighlight lang="c#">
class PaymentInfo
{
public string PaymentMethod { get; set; }
public string ChequeNo { get; set; }
public decimal Amount { get; set; }
}
 
public void NewCashSaleWithMultiPayments(BCE.Data.DBSetting dbSetting)
{
BCE.AutoCount.Invoicing.Sales.CashSale.CashSaleCommand cmd =
BCE.AutoCount.Invoicing.Sales.CashSale.CashSaleCommand.Create(dbSetting);
BCE.AutoCount.Invoicing.Sales.CashSale.CashSale doc = cmd.AddNew();
BCE.AutoCount.Invoicing.Sales.CashSale.CashSaleDetail dtl;
List<PaymentInfo> payments = new List<PaymentInfo>();
 
//doc.DocNo = "CS-00011";
doc.DebtorCode = "300-C001";
doc.DocDate = DateTime.Today.Date;
 
doc.IsRoundAdj = true;
 
dtl = doc.AddDetail();
dtl.ItemCode = "FG00001";
dtl.Qty = 1;
dtl.UOM = "UNIT";
dtl.UnitPrice = 50.20M;
dtl.TaxType = "S-10";
 
dtl = doc.AddDetail();
dtl.ItemCode = "FG00002";
dtl.Qty = 10;
dtl.UOM = "UNIT";
dtl.UnitPrice = 60.20M;
dtl.Discount = "30%";
dtl.TaxType = "S-10";
 
//Create payments with collection of PaymentInfo
payments.AddRange(new PaymentInfo[] {
new PaymentInfo()
{
PaymentMethod = "CASH",
Amount = 18M
},
new PaymentInfo()
{
PaymentMethod = "MASTER",
ChequeNo = "MB1839232",
Amount = 500.75M
}
});
 
MakeMultiPayments(doc, payments, dbSetting);
 
try
{
doc.Save();
BCE.Application.AppMessage.ShowMessage($"{doc.DocNo} is created.");
}
catch (Exception ex)
{
BCE.Application.AppMessage.ShowErrorMessage($"Failed to save Cash Sale.\n{ex.Message}");
}
}
 
private void MakeMultiPayments(BCE.AutoCount.Invoicing.Sales.CashSale.CashSale cs, List<PaymentInfo> payments, BCE.Data.DBSetting dbSetting)
{
BCE.AutoCount.ARAP.ARPayment.ARPaymentDTLEntity payDtl;
 
//PaymentMode 3 indicate the cash sale is paid by more than one type of payments.
cs.PaymentMode = 3;
 
//cs.CashPayment = 0M;
cs.CCApprovalCode = DBNull.Value;
cs.CashSalePayment.ARPayment.ClearDetails();
 
cs.CashSalePayment = BCE.AutoCount.Invoicing.Sales.SalesPayment.Create(
cs.ReferPaymentDocKey, cs.DocKey,
BCE.AutoCount.Document.DocumentType.CashSale, dbSetting);
 
cs.CashSalePayment.DebtorCode = cs.DebtorCode;
cs.CashSalePayment.CurrencyCode = cs.CurrencyCode;
cs.CashSalePayment.DocDate = cs.DocDate;
 
payments.ForEach(p =>
{
payDtl = cs.CashSalePayment.ARPayment.NewDetail();
payDtl.PaymentMethod = p.PaymentMethod;
payDtl.ChequeNo = p.ChequeNo;
payDtl.PaymentAmt = p.Amount;
});
 
if (cs.CashSalePayment.PaymentAmt > 0)
cs.ReferPaymentDocKey = cs.CashSalePayment.DocKey;
}
</syntaxhighlight>
</tabber>
<br/>
*Use method '''GetFirstCashAccount(BCE.Data.DBSetting)''' can retrieve the first row of the payment type that is Cash.
<syntaxhighlight lang="c#">
//Get the first row payment type that is "CASH"
//Must have a Payment Method's "Payment Type" that is "CASH"
//in General Maintenance | Payment Method Maintenance
payDtl.PaymentMethod = BCE.AutoCount.Invoicing.CommonFunction.GetFirstCashAccount(dbSetting);
</syntaxhighlight>
 
 
<br/>
{{SeeAlsoSale}}
{{NavigateDeveloper}}