
;;--------- Auto Payment for Purchase

[#Form: Purchase Color]

	Add : On : At End : Form Accept   : Yes : CALL : PaymentVchCreate 

[#Object: Voucher]

	PayPayBillName1: $$CollectionField:$PayBillName:1:LedgerEntries
	PayPayBillAmt1 : $$CollectionField:$PayBillAmt:1:LedgerEntries
	
[#Object: LedgerEntry]

	PayBillName	: $$CollectionField:$Name:1:BillAllocations
	PayBillAmt 	: $$CollectionField:$Amount:1:BillAllocations
	PayVTypeName: $PayRcptVchType

[Function: PaymentVchCreate]

;; Variable	Block

	Variable	: PayCardLedger	: String
	Variable	: PayCardAmount	: Amount
	Variable	: PayCardNumber	: String
	
	Variable	: BankLedger	: String
	Variable	: ChequeAmount	: Amount
	Variable	: ChequeBank	: String
	Variable	: ChequeNo		: String
	Variable	: ChequeDate	: Date
	
	Variable	: CashLedger	: String
	Variable	: CashAmount	: Amount
	
	Variable	: VchType		: String
	Variable	: VchCostCentre	: String

	Variable	: VchDate		: Date	
	Variable	: VchNarration	: String
	Variable	: VCHAmount		: Amount
	Variable	: VCHNumber		: String

;; Procedural Block
		
	010	: Set	: PayCardLedger	: $POSCardLedger 
	020	: Set	: PayCardAmount	: $PayPOSCardAmount
	030	: Set	: PayCardNumber	: $POSCardNumber
	
	040	: Set	: BankLedger	: $POSChequeLedger
	050	: Set	: ChequeAmount	: $PayPOSBankAmount
	060	: Set	: ChequeBank	: $POSChequeBankName
	070	: Set	: ChequeNo		: $POSChequeNumber
	080	: Set	: ChequeDate	: $POSChequeDate
	
	090	: Set	: CashLedger	: $POSCashLedger
	100	: Set	: CashAmount	: $PayPOSCashAmount
	
	110	: Set	: VchType		: $$VchTypePayment
	
	115	: Set	: VchCostCentre	: $AutoCostLevel
			
	120	: SET	: VchDate		: $DATE
	130 : SET 	: VCHAmount		: ##PayCardAmount + ##ChequeAmount + ##CashAmount
	140 : SET	: VchNarration	: "Bill No.: " + $$String:$VoucherNumber ;+ " Payment Received " ;+ $$String:##PayCardNumber
	141	: Set	: VCHNumber		: $VoucherNumber

	150 : QUERYBOX : "Create Payment Voucher ?":Yes:No

	160	: IF : $$LastResult 

	170	: NEW OBJECT : VOUCHER

	180	:   SET VALUE	: Date						: ##VchDate
	185	:   Set Value	: AUTOCOSTLEVEL				: ##VchCostCentre
	190	:   SET VALUE	: VoucherTypeName			: ##VchType 
	200 :   SET 		: SVViewName				: $$SysName:AcctgVchView

	210	: 		INSERT COLLECTION OBJECT				: AllLedgerEntries
	220	:		SET VALUE		: LedgerName			: $PartyLedgerName
	230	: 		SET VALUE		: Amount				: -1 * ##VCHAmount
	240	: 		SET VALUE		: Is Deemed Positive	: "Yes"

	250	: 			INSERT COLLECTION OBJECT				: BillAllocations
	260	:				SET VALUE		: Name					: ##VCHNumber;;$PayPayBillName1 
	270	:   			SET VALUE 		: BillType				: "AgstRef"
	280	: 				SET VALUE		: Amount				: -1 * ##VCHAmount
	290	: 				SET TARGET		: ...
	
	300	: If	: NOT $$IsSysName:##PayCardLedger
	310	:   	INSERT COLLECTION OBJECT				: AllLedgerEntries
	320	:		SET VALUE		: LedgerName			: ##PayCardLedger
	330	: 		SET VALUE		: Amount				: -1 * ##PayCardAmount
	340	: 		SET VALUE		: Is Deemed Positive	: "No"
	350	: 		SET TARGET		: ..
	360	: End If

	370	: If	: NOT $$IsSysName:##BankLedger
	380	:   	INSERT COLLECTION OBJECT				: AllLedgerEntries
	390	:		SET VALUE		: LedgerName			: ##BankLedger
	400	: 		SET VALUE		: Amount				: -1 * ##ChequeAmount
	410	: 		SET VALUE		: Is Deemed Positive	: "No"
	
	420	: 			INSERT COLLECTION OBJECT				: BankAllocations
	430	:				SET VALUE		: BankName			: ##ChequeBank
	440	:   			SET VALUE 		: InstrumentNumber	: ##ChequeNo
	450	:   			SET VALUE 		: InstrumentDate	: ##ChequeDate
	460	: 				SET VALUE		: Amount			: -1 * ##ChequeAmount
	470	: 				SET TARGET		: ...
	480	: End If
	
	490	: If	: NOT $$IsSysName:##CashLedger
	500	:   	INSERT COLLECTION OBJECT				: AllLedgerEntries
	510	:		SET VALUE		: LedgerName			: ##CashLedger
	520	: 		SET VALUE		: Amount				: -1 * ##CashAmount
	530	: 		SET VALUE		: Is Deemed Positive	: "No"
	540	: 		SET TARGET		: ..
	550	: End If
	551	: Set Value	: Narration	: ##VchNarration

	560 :   SET VALUE : PersistedView : ##SVViewName
	570	: 	CREATE TARGET
	
	580	:  ENDIF 

;; End-of-File  


/*[#Field: EI ValueTotal]
	Add	: Sub Form	: NSVchPayments	: @@IsSales*/
	
	[#Part: DBLLINE Narration]
		
		Add	: Lines	: After 		: VCH ShowStatutoryDetails : PayVchPayments
		Add	: Lines	: At Beginning	: PayVchAdvPayments

	[Line	: PayVchPayments]
		Field           : Medium Prompt, PayVchPayments
		Local           : Field : Medium Prompt  : Set as    : $$LocaleString:"Payment Details"
		Invisible		: NOT @@IsPurchase
	
	[Field	: PayVchPayments]
		Use	: Short Name Field
		Sub Form	: PayVchPayments	
		Read Only	: Yes
	
[Line	: PayVchAdvPayments]
		Field           : Medium Prompt, PayVchPayments
		Local           : Field : Medium Prompt  : Set as    : $$LocaleString:"Payment Details"
		Invisible		: NOT @@IsSalesOrder
	
[Report	: PayVchPayments]
	Form	: PayVchPayments
	
	[Form	: PayVchPayments]
		Height	: 35% Screen
		Width	: 80% Screen
		Part	: PayVchPayments
		
		[Part   : PayVchPayments]
			Lines	: Form SubTitle, PayVch POS Advance, PayVCH POS Card Payment, PayVCH POS Bank Payment, PayVCH POS Cash Payment, PayVCH PartyOS
			Local	: Field	: Form SubTitle	: Set as	: "Payment Details"
			Local	: Line	: Default		: Space Top		: 0.30
			Local	: Line	: Default		: Space Bottom	: 0.30
			
	[Line	: PayVch POS Advance]
		Field           : Medium Prompt, PayVch POS Advance
		Local           : Field : Medium Prompt 	: Set as                : $$LocaleString:"Last Advance Amount"
		Invisible		: @@IsSalesOrder;;##SVVoucherType = $$VchTypeSalesOrder

		[Field	: PayVch POS Advance]
			Use	: Amount Forex Field
			Storage	: PayVch POS Advance
			Set Always: Yes
			Validate	: #PayVCHPartyOS > = 0
			
;; ---- Card Payment ----

[Line: PayVCH POS Card Payment]

		Field           : VCH POS CardDeemedPos, Short Prompt, PayVCH POSCardLedger, PayVCH POSCardAmount
		Field           : Medium Prompt, PayVCH POS CardNumber
		Local           : Field : Short Prompt                  : Set as                : $$LocaleString:"Card Payment"
		Local           : Field : Medium Prompt                 : Set as                : $$LocaleString:"Card No :"

	[Field: PayVCH POSCardLedger]

		Use         : Name Field
;		Set as      : If $$IsEmpty:$LedgerName OR $$IsEmpty:#PayVCHPOSCardAmount Then $$SysName:NotApplicable Else $LedgerName
		Storage     : POSCardLedger
		Set Always	: Yes
		Table       : POS Bank Ledgers Extract, NOT Applicable
		Keys        : Create Ledger, Alter Ledger
		Variable    : SV Ledger
		Width       : @@VCHNameWidth
		Show Table  : On Blank
		
	[Field: PayVCH POSCardAmount]

		Use         : Amount Forex Field
		Storage     : PayPOSCardAmount
		Set Always	: Yes
		Width       : @@AmountWidth
		Format      : "Symbol, No Zero, " + ##ShowForex 
;;		Skip        : $$IsEmpty:#PayVCHPOSCardAmount
		Inactive    : $$IsNotApplicable:#PayVCHPOSCardLedger OR $$IsEmpty:#PayVCHPOSCardLedger
		;Set as      : If $$InCreateMode then (#EIValueTotal - #PayVchPOSAdvance) Else $$Value
		;$$IsNegative:#EIValueTotal Then 0 Else if NOT @@InvoiceInCreate then $$Value else +
;					  (If NOT $$IsFieldEdited Then #EIValueTotal  Else $$Value)
		Validate	: #PayVCHPartyOS > = 0
      
	[Field: PayVCH POS CardNumber]

			Use             : Name Field
			Storage         : POSCardNumber
			Set Always		: Yes
			Skip            : $$IsEmpty:#PayVCHPOSCardAmount 
			Width           : @@Amountwidth * 2
;			Inactive        : $$IsEmpty:#PayVCHPOSCardAmount 

	[Line: PayVCH POS Bank Payment]

			Field           : VCH POS BankDeemedPos, Short Prompt, PayVCH POSBankLedger, PayVCH POSBankAmount
			Field           : Medium Prompt, PayVCH POS ChequeBank, Simple Prompt, PayVCH POS ChequeNo 
			Fields			: Long Prompt, PayVch POS ChequeDt
			Local           : Field : Short Prompt                  : Set as                : $$LocaleString:"Cheque" + ":"
			Local           : Field : Medium Prompt                 : Set as                : If $$IsNOTApplicable:#PayVCHPOSBankLedger OR $$IsEmpty:#PayVCHPOSBankAmount Then " " Else $$LocaleString:"Bank Name" + ":"
			Local           : Field : Simple Prompt                 : Set as                : If $$IsNOTApplicable:#PayVCHPOSBankLedger OR $$IsEmpty:#PayVCHPOSBankAmount Then " " Else $$LocaleString:"Ch No : "
			Local           : Field : Simple Prompt                 : Width                 : 7
			Local			: Field : Long Prompt					: Set as				: "Date"
			Local			: Field : Long Prompt					: Width					: 5

		[Field: PayVCH POSBankLedger]

			Use         : Name field
			Storage     : POSChequeLedger
			Set Always	: Yes
			Table       : POS Bank Ledgers Extract, NOT Applicable
			Keys        : Create Ledger, Alter Ledger
			Variable    : SV Ledger
			Width       : @@VCHNameWidth
			Show Table  : On Blank
;			Skip        : $$NettAmount:#VCHPOSCardAmount:#VCHPOSCouponAmount = #VCHPOSInvoiceTotal OR $$IsNegative:#VCHPOSInvoiceTotal

		[Field: PayVCH POSBankAmount]

			Use         : Amount Forex Field
			Storage     : PayPOSBankAmount
			Set Always	: Yes
			Format      : "Symbol, No Zero," + ##ShowForex  
			Inactive    : $$IsNotApplicable:#PayVCHPOSBankLedger 
		Validate	: #PayVCHPartyOS > = 0

		[Field: PayVCH POS ChequeNo]

			Use         : Name Field
			Storage     : POSChequeNumber
			Set Always	: Yes
			Skip        : $$IsEmpty:#PayVCHPOSBankAmount 
			Inactive    : $$IsEmpty:#PayVCHPOSBankAmount  
			Width		: @@NumberWidth
	
		[Field	: PayVch POS ChequeDt]
			Use         : Uni Date Field
			Storage         : POSChequeDate
			Set Always	: Yes
			Skip            : $$IsEmpty:#PayVCHPOSBankAmount 
			Inactive        : $$IsEmpty:#PayVCHPOSBankAmount  
			Width		: @@NumberWidth
			
		[Field: PayVCH POS ChequeBank]

			Use         : Name Field
			Storage         : POSChequeBankName
			Set Always	: Yes
			Skip            : $$IsEmpty:#PayVCHPOSBankAmount  
			Inactive        : $$IsEmpty:#PayVCHPOSBankAmount  
 
	[Line: PayVCH POS Cash Payment]

			Field           : VCH POS  CashDeemedPos, Short Prompt, PayVCH POSCashLedger, PayVCH POSCashAmount
			Field           : Medium Prompt, PayVCH POS MoneyTendered
			Field           : Simple Prompt, PayVCH POS Balance
			Local           : Field : Short Prompt                  : Set as        : $$LocaleString:"Cash"
			Local           : Field : Medium Prompt                 : Set as        : If $$IsNOTApplicable:#PayVCHPOSCashLedger Then " " Else $$LocaleString:"Cash Tendered :"
			Local           : Field : Simple Prompt                 : Set as        : If $$IsNOTApplicable:#PayVCHPOSCashLedger Then " " Else $$LocaleString:"Balance" + ":"
			Local           : Field : Simple Prompt                 : Width         : 8

		[Field: PayVCH POSCashLedger]

			Use         : Name Field
			Storage     : POSCashLedger
			Set Always	: Yes
			Table       : POS Cash Ledgers Extract, NOT Applicable  
			Keys        : Create Ledger, Alter Ledger
			Variable    : SV Ledger
			Width       : @@VCHNameWidth
			Show Table  : On Blank

		[Field: PayVCH POSCashAmount]

			Use         : Amount Forex Field
			Storage     : PayPOSCashAmount
			Set Always	: Yes
			Format      : "Symbol, No Zero," + ##ShowForex  
			
			Inactive    : $$IsNOTApplicable:#PayVCHPOSCashLedger OR $$IsEmpty:#PayVCHPOSCashLedger
			Skip        : $$IsNotApplicable:#PayVCHPOSCashLedger 							  
			Validate	: #PayVCHPartyOS > = 0

		[Field: PayVCH POS MoneyTendered]

			Use             : Amount Forex Field
			Storage         : POSCashReceived                         
			Validate        : $$Value >= $$AsPositive:#PayVCHPOSCashAmount 
			Format      	: "Symbol, No Zero," + ##ShowForex
			Set Always      : Yes
			Skip        	: $$IsNotApplicable:#PayVCHPOSCashLedger
						

		[Field: PayVCH POS Balance]

			Use             : Amount Forex Field
			Set as          : If NOT $$IsEmpty:#PayVCHPOSCashAmount AND #PayVCHPOSMoneyTendered > $$AsPositive:#PayVCHPOSCashAmount Then $POSCashReceived - $$AsPositive:#PayVCHPOSCashAmount Else ""							  
			Set Always      : Yes
			Skip            : Yes
			Format      	: "Symbol, No Zero," + ##ShowForex  

	[Line	: PayVCH PartyOS]
		Field	: Short Prompt, PayVCH PartyOS
		Field	: Medium Prompt, PayRcpt VchType
		Local   : Field : Short Prompt   : Set as   : $$LocaleString:"Outstanding"
		Local	: Field	: Medium Prompt	 : Set as	: "Rcpt. Vch. Type"
		Local	: Field : AdvRcpt VchType: Skip on	: ($$IsNotApplicable:#PayVCHPOSCardLedger AND $$IsNotApplicable:#PayVCHPOSBankLedger AND $$IsNotApplicable:#PayVCHPOSCashLedger)
				   		
	[Field: PayRcpt VchType]

			Use			: Name Field
			Storage		: PayRcptVchType
			Set Always	: Yes
			Table		: PayPaymentVoucherTypes
			Show Table	: On Blank

[Collection: PayPaymentVoucherTypes]

		Use			: Alias Collection
		Title       : $$LocaleString:"List of Voucher Types"
		Type        : Voucher Type
		Child of    : $$VchTypePayment
		BelongsTo  	: Yes
		Client Only	: Yes
	
	[Field	: PayVCH PartyOS]
		Use			: Amount Forex Field
		Storage		: PayVCPartyOS 
		Set Always 	: Yes
		Set As		: @VETotal
		VETotal		: (#EIValueTotal - #PayVchPOSAdvance) - (#PayVCHPOSCardAmount + #PayVCHPOSBankAmount + #PayVCHPOSCashAmount) 
		Read Only	: Yes

[System	: UDF]
	
	PayPOSCardAmount	: Amount	: 2001
	PayPOSBankAmount	: Amount	: 2002
	PayPOSCashAmount	: Amount	: 2003
	
	PayVCPartyOS		: Amount	: 2004
	POSChequeDate		: Date		: 2005
	PayVchPOSAdvance	: Amount	: 2006
	PayRcpt VchType		: String	: 2007

