issue #23241: use uptodate database source
authorSteve Hackbarth <stephenhackbarth@gmail.com>
Wed, 9 Apr 2014 01:14:42 +0000 (21:14 -0400)
committerSteve Hackbarth <stephenhackbarth@gmail.com>
Wed, 9 Apr 2014 01:14:42 +0000 (21:14 -0400)
1085 files changed:
foundation-database/manifest.js
foundation-database/public/functions/acknowledgemessage.sql
foundation-database/public/functions/actcost.sql
foundation-database/public/functions/addrusecount.sql
foundation-database/public/functions/addtaxtoglseries.sql
foundation-database/public/functions/addtopackinglistbatch.sql
foundation-database/public/functions/adjustinvvalue.sql
foundation-database/public/functions/adjustments.sql
foundation-database/public/functions/allocatedforso.sql
foundation-database/public/functions/allocatedforwo.sql
foundation-database/public/functions/alterencrypt.sql
foundation-database/public/functions/apaging.sql
foundation-database/public/functions/apapplied.sql
foundation-database/public/functions/apcheckpending.sql
foundation-database/public/functions/apcurrgain.sql
foundation-database/public/functions/applyapcreditmemotobalance.sql
foundation-database/public/functions/applyapcredits.sql
foundation-database/public/functions/applyarcreditmemotobalance.sql
foundation-database/public/functions/applycashreceiptlinebalance.sql
foundation-database/public/functions/applycashreceipttobalance.sql
foundation-database/public/functions/araging.sql
foundation-database/public/functions/arapplied.sql
foundation-database/public/functions/archivesaleshistory.sql
foundation-database/public/functions/arcurrgain.sql
foundation-database/public/functions/asofinvbal.sql
foundation-database/public/functions/asofinvnn.sql
foundation-database/public/functions/asofinvqty.sql
foundation-database/public/functions/assessfinancecharge.sql [new file with mode: 0644]
foundation-database/public/functions/attachcontact.sql
foundation-database/public/functions/attachquotetoopportunity.sql
foundation-database/public/functions/attachsalesordertoopportunity.sql
foundation-database/public/functions/averagesalesprice.sql
foundation-database/public/functions/avgcost.sql
foundation-database/public/functions/balanceitemsite.sql
foundation-database/public/functions/basecurrid.sql
foundation-database/public/functions/bomcontains.sql
foundation-database/public/functions/bomhistsequence.sql
foundation-database/public/functions/bomitem.sql
foundation-database/public/functions/bomlevelbyitem.sql
foundation-database/public/functions/bomworkeffective.sql
foundation-database/public/functions/bomworkexpired.sql
foundation-database/public/functions/bomworkitemsequence.sql
foundation-database/public/functions/bomworksequence.sql
foundation-database/public/functions/buildinvbal.sql
foundation-database/public/functions/calcbillingamts.sql
foundation-database/public/functions/calccashbudget.sql
foundation-database/public/functions/calccreditmemoamts.sql
foundation-database/public/functions/calcinvoiceamt.sql [new file with mode: 0644]
foundation-database/public/functions/calcpendingarapplications.sql
foundation-database/public/functions/calcpurchaseorderamt.sql [new file with mode: 0644]
foundation-database/public/functions/calcpurchaseorderduedate.sql [new file with mode: 0644]
foundation-database/public/functions/calcquoteamt.sql
foundation-database/public/functions/calcsalesorderamt.sql
foundation-database/public/functions/calcshipfreight.sql
foundation-database/public/functions/calctotalslipqty.sql
foundation-database/public/functions/calculatefreightdetail.sql
foundation-database/public/functions/calculatesubtax.sql
foundation-database/public/functions/calculatetax.sql
foundation-database/public/functions/calculatetaxdetail.sql
foundation-database/public/functions/calculatetaxdetailline.sql
foundation-database/public/functions/calculatetaxdetailsummary.sql
foundation-database/public/functions/calculatetaxhist.sql
foundation-database/public/functions/calcvoucheramts.sql
foundation-database/public/functions/calcwooperstartstub.sql
foundation-database/public/functions/cancelbillingselection.sql
foundation-database/public/functions/changeaccountingperioddates.sql
foundation-database/public/functions/changeaccountingyearperioddates.sql
foundation-database/public/functions/changefkeypointers.sql
foundation-database/public/functions/changepoitemduedate.sql
foundation-database/public/functions/changepoitemqty.sql
foundation-database/public/functions/changeprdate.sql
foundation-database/public/functions/changeprqty.sql
foundation-database/public/functions/changepseudofkeypointers.sql
foundation-database/public/functions/changepurchasedropship.sql [new file with mode: 0644]
foundation-database/public/functions/changewodates.sql
foundation-database/public/functions/changewoproject.sql
foundation-database/public/functions/changewoqty.sql
foundation-database/public/functions/characteristicstostring.sql
foundation-database/public/functions/checkcreditmemositeprivs.sql
foundation-database/public/functions/checkdetailformatted.sql
foundation-database/public/functions/checkinvoicesiteprivs.sql
foundation-database/public/functions/checkpositeprivs.sql
foundation-database/public/functions/checkprivilege.sql
foundation-database/public/functions/checkquotesiteprivs.sql
foundation-database/public/functions/checkrasiteprivs.sql
foundation-database/public/functions/checkshipmentsiteprivs.sql
foundation-database/public/functions/checksositeprivs.sql
foundation-database/public/functions/checkvouchersiteprivs.sql
foundation-database/public/functions/clearnumberissue.sql
foundation-database/public/functions/clearpayment.sql
foundation-database/public/functions/closeaccountingperiod.sql
foundation-database/public/functions/closeaccountingyearperiod.sql
foundation-database/public/functions/closepo.sql
foundation-database/public/functions/closewo.sql
foundation-database/public/functions/cntct.sql
foundation-database/public/functions/cntctdups.sql
foundation-database/public/functions/cntctmerge.sql
foundation-database/public/functions/cntctrestore.sql
foundation-database/public/functions/cntctselect.sql
foundation-database/public/functions/cntctselectcol.sql
foundation-database/public/functions/cntctused.sql
foundation-database/public/functions/coheadstatecolor.sql
foundation-database/public/functions/compareversion.sql [new file with mode: 0644]
foundation-database/public/functions/concatagg.sql
foundation-database/public/functions/consolidatelocations.sql
foundation-database/public/functions/convertcustomertoprospect.sql
foundation-database/public/functions/convertprospecttocustomer.sql
foundation-database/public/functions/convertquote.sql
foundation-database/public/functions/convertquotetoinvoice.sql
foundation-database/public/functions/copybom.sql
foundation-database/public/functions/copybudget.sql
foundation-database/public/functions/copycmd.sql
foundation-database/public/functions/copycontract.sql
foundation-database/public/functions/copyfinancialgroup.sql
foundation-database/public/functions/copyglseries.sql
foundation-database/public/functions/copyincdt.sql
foundation-database/public/functions/copyinvoice.sql
foundation-database/public/functions/copyitem.sql
foundation-database/public/functions/copyitemsite.sql
foundation-database/public/functions/copylocale.sql
foundation-database/public/functions/copypo.sql
foundation-database/public/functions/copypricingschedule.sql
foundation-database/public/functions/copyprj.sql
foundation-database/public/functions/copyproject.sql
foundation-database/public/functions/copyquote.sql
foundation-database/public/functions/copyso.sql
foundation-database/public/functions/copytodoitem.sql
foundation-database/public/functions/copyvoucher.sql
foundation-database/public/functions/correctporeceipt.sql
foundation-database/public/functions/correctproduction.sql
foundation-database/public/functions/correctreceipt.sql
foundation-database/public/functions/cosbycustomervalue.sql
foundation-database/public/functions/costsbycustomerbyitemsite.sql
foundation-database/public/functions/costsbycustomervalue.sql
foundation-database/public/functions/createaccountingperiod.sql
foundation-database/public/functions/createaccountingyearperiod.sql
foundation-database/public/functions/createapchecks.sql
foundation-database/public/functions/createapcreditmemo.sql
foundation-database/public/functions/createapcreditmemoapplication.sql
foundation-database/public/functions/createapdebitmemo.sql
foundation-database/public/functions/createapdiscount.sql
foundation-database/public/functions/createarcashdeposit.sql
foundation-database/public/functions/createarcreditmemo.sql
foundation-database/public/functions/createardebitmemo.sql
foundation-database/public/functions/createbillingheader.sql
foundation-database/public/functions/createbomitem.sql
foundation-database/public/functions/createcheck.sql
foundation-database/public/functions/createchecks.sql
foundation-database/public/functions/createcounttag.sql
foundation-database/public/functions/createcyclecountsbywarehouse.sql
foundation-database/public/functions/createcyclecountsbywarehousebyclasscode.sql
foundation-database/public/functions/createcyclecountsbywarehousebyplannercode.sql
foundation-database/public/functions/createinvoice.sql
foundation-database/public/functions/createinvoiceconsolidated.sql
foundation-database/public/functions/createinvoices.sql
foundation-database/public/functions/createmiscapcheck.sql
foundation-database/public/functions/createpkgschema.sql
foundation-database/public/functions/createpr.sql
foundation-database/public/functions/createpriv.sql
foundation-database/public/functions/createpurchasetosale.sql
foundation-database/public/functions/createrecurringinvoices.sql
foundation-database/public/functions/createrecurringitems.sql
foundation-database/public/functions/createtodoitem.sql
foundation-database/public/functions/createuser.sql
foundation-database/public/functions/createwo.sql
foundation-database/public/functions/createwomaterial.sql
foundation-database/public/functions/creditmemototal.sql
foundation-database/public/functions/crmacct.sql
foundation-database/public/functions/currconcat.sql
foundation-database/public/functions/currentapmemonumber.sql
foundation-database/public/functions/currentarmemonumber.sql
foundation-database/public/functions/currentcashrcptnumber.sql
foundation-database/public/functions/currentnumber.sql
foundation-database/public/functions/currgain.sql
foundation-database/public/functions/currrate.sql
foundation-database/public/functions/currtobase.sql
foundation-database/public/functions/currtocurr.sql
foundation-database/public/functions/currtolocal.sql
foundation-database/public/functions/custitem.sql
foundation-database/public/functions/customercanpurchase.sql
foundation-database/public/functions/defaultlocationname.sql
foundation-database/public/functions/deleteaccount.sql
foundation-database/public/functions/deleteaccountingperiod.sql
foundation-database/public/functions/deleteaccountingyearperiod.sql
foundation-database/public/functions/deleteaddress.sql
foundation-database/public/functions/deleteapcheck.sql
foundation-database/public/functions/deletebankadjustmenttype.sql
foundation-database/public/functions/deletebankreconciliation.sql
foundation-database/public/functions/deletebom.sql
foundation-database/public/functions/deletebomworkset.sql
foundation-database/public/functions/deletebudget.sql
foundation-database/public/functions/deletebudgetitems.sql
foundation-database/public/functions/deletecashrcpt.sql
foundation-database/public/functions/deletecharacteristic.sql
foundation-database/public/functions/deletecheck.sql
foundation-database/public/functions/deleteclasscode.sql
foundation-database/public/functions/deletecompany.sql
foundation-database/public/functions/deletecreditmemo.sql
foundation-database/public/functions/deletecustomer.sql
foundation-database/public/functions/deletecustomertype.sql
foundation-database/public/functions/deleteempgrp.sql
foundation-database/public/functions/deleteexpiredips.sql
foundation-database/public/functions/deleteflgroup.sql
foundation-database/public/functions/deleteform.sql
foundation-database/public/functions/deletefreightclass.sql
foundation-database/public/functions/deleteglseries.sql
foundation-database/public/functions/deleteincident.sql
foundation-database/public/functions/deleteinvoice.sql
foundation-database/public/functions/deleteipsitem.sql
foundation-database/public/functions/deleteipsprodcat.sql
foundation-database/public/functions/deleteitem.sql
foundation-database/public/functions/deleteitemcost.sql
foundation-database/public/functions/deleteitemsite.sql
foundation-database/public/functions/deleteitemuom.sql
foundation-database/public/functions/deleteitemuomconv.sql
foundation-database/public/functions/deletelocation.sql
foundation-database/public/functions/deletemetasql.sql
foundation-database/public/functions/deleteopenrecurringitems.sql
foundation-database/public/functions/deleteopportunity.sql
foundation-database/public/functions/deletepackage.sql
foundation-database/public/functions/deletepo.sql
foundation-database/public/functions/deletepoitem.sql
foundation-database/public/functions/deletepr.sql
foundation-database/public/functions/deleteproductcategory.sql
foundation-database/public/functions/deleteprofitcenter.sql
foundation-database/public/functions/deleteproject.sql
foundation-database/public/functions/deleteprojecttask.sql
foundation-database/public/functions/deleteqryhead.sql
foundation-database/public/functions/deletequote.sql
foundation-database/public/functions/deletequoteitem.sql [new file with mode: 0644]
foundation-database/public/functions/deleterecvfororder.sql
foundation-database/public/functions/deletesalescategory.sql
foundation-database/public/functions/deleteshippingcharge.sql
foundation-database/public/functions/deleteshippingchargetype.sql
foundation-database/public/functions/deleteshipto.sql
foundation-database/public/functions/deleteso.sql
foundation-database/public/functions/deletesoitem.sql
foundation-database/public/functions/deletestandardjournal.sql
foundation-database/public/functions/deletestandardjournalgroup.sql
foundation-database/public/functions/deletesubaccount.sql
foundation-database/public/functions/deletesubaccounttype.sql
foundation-database/public/functions/deletetax.sql
foundation-database/public/functions/deletetaxclass.sql
foundation-database/public/functions/deletetaxtype.sql
foundation-database/public/functions/deletetaxzone.sql
foundation-database/public/functions/deletetodoitem.sql
foundation-database/public/functions/deleteunusedclasscodes.sql
foundation-database/public/functions/deleteunusedfreightclasses.sql
foundation-database/public/functions/deleteunusedproductcategories.sql
foundation-database/public/functions/deleteuom.sql
foundation-database/public/functions/deleteuomconv.sql
foundation-database/public/functions/deleteuserpreference.sql
foundation-database/public/functions/deletevendoraddr.sql
foundation-database/public/functions/deletevendortype.sql
foundation-database/public/functions/deletewo.sql
foundation-database/public/functions/deletewomaterial.sql
foundation-database/public/functions/detachccpayfromso.sql
foundation-database/public/functions/detachcontact.sql
foundation-database/public/functions/detag.sql
foundation-database/public/functions/detailednnqoh.sql
foundation-database/public/functions/detailedqoh.sql
foundation-database/public/functions/determinediscountdate.sql
foundation-database/public/functions/determineduedate.sql
foundation-database/public/functions/disablepackage.sql
foundation-database/public/functions/distributeitemlocseries.sql
foundation-database/public/functions/distributetodefault.sql
foundation-database/public/functions/distributetodefaultitemloc.sql
foundation-database/public/functions/distributetolocations.sql
foundation-database/public/functions/distributevoucherline.sql
foundation-database/public/functions/dopostcosts.sql
foundation-database/public/functions/doupdatecosts.sql
foundation-database/public/functions/dropifexists.sql
foundation-database/public/functions/editccnumber.sql
foundation-database/public/functions/enablepackage.sql
foundation-database/public/functions/endoftime.sql
foundation-database/public/functions/entercount.sql
foundation-database/public/functions/enterporeceipt.sql
foundation-database/public/functions/enterporeturn.sql
foundation-database/public/functions/enterreceipt.sql
foundation-database/public/functions/expirecreditcard.sql
foundation-database/public/functions/explodebom.sql
foundation-database/public/functions/explodekit.sql
foundation-database/public/functions/explodephantomorder.sql
foundation-database/public/functions/explodewo.sql
foundation-database/public/functions/explodewoeffective.sql
foundation-database/public/functions/fetchapmemonumber.sql
foundation-database/public/functions/fetcharmemonumber.sql
foundation-database/public/functions/fetchcashrcptnumber.sql
foundation-database/public/functions/fetchcmnumber.sql
foundation-database/public/functions/fetchcrmaccountnumber.sql
foundation-database/public/functions/fetchdefaultfob.sql
foundation-database/public/functions/fetchdefaultshipvia.sql
foundation-database/public/functions/fetchglsequence.sql
foundation-database/public/functions/fetchincidentnumber.sql
foundation-database/public/functions/fetchinvcnumber.sql
foundation-database/public/functions/fetchitemuomconvtypes.sql
foundation-database/public/functions/fetchjournalnumber.sql
foundation-database/public/functions/fetchmetricbool.sql
foundation-database/public/functions/fetchmetrictext.sql
foundation-database/public/functions/fetchmetricvalue.sql
foundation-database/public/functions/fetchnextchecknumber.sql
foundation-database/public/functions/fetchnextnumber.sql
foundation-database/public/functions/fetchponumber.sql
foundation-database/public/functions/fetchprefwarehousid.sql
foundation-database/public/functions/fetchprnumber.sql
foundation-database/public/functions/fetchqunumber.sql
foundation-database/public/functions/fetchshipmentnumber.sql
foundation-database/public/functions/fetchsonumber.sql
foundation-database/public/functions/fetchtonumber.sql
foundation-database/public/functions/fetchusrprefbool.sql
foundation-database/public/functions/fetchvonumber.sql
foundation-database/public/functions/fetchwonumber.sql
foundation-database/public/functions/financialreport.sql
foundation-database/public/functions/findapaccount.sql
foundation-database/public/functions/findapdiscountaccount.sql
foundation-database/public/functions/findapprepaidaccount.sql
foundation-database/public/functions/findaraccount.sql
foundation-database/public/functions/findardiscountaccount.sql
foundation-database/public/functions/findcalendarorigin.sql
foundation-database/public/functions/findcustomerform.sql
foundation-database/public/functions/finddeferredaccount.sql
foundation-database/public/functions/findfreightaccount.sql
foundation-database/public/functions/findperiodend.sql
foundation-database/public/functions/findperiodstart.sql
foundation-database/public/functions/findprepaidaccount.sql
foundation-database/public/functions/findsalesaccnt.sql
foundation-database/public/functions/findspecialfinancial.sql
foundation-database/public/functions/firstline.sql
foundation-database/public/functions/fixacl.sql
foundation-database/public/functions/formatabachecks.sql
foundation-database/public/functions/formatachchecks.sql
foundation-database/public/functions/formatachcompanyid.sql
foundation-database/public/functions/formataddr.sql
foundation-database/public/functions/formatboolyn.sql
foundation-database/public/functions/formatbooseq.sql
foundation-database/public/functions/formatbytea.sql
foundation-database/public/functions/formatccdashes.sql
foundation-database/public/functions/formatccnumber.sql
foundation-database/public/functions/formatcntctname.sql
foundation-database/public/functions/formatcost.sql
foundation-database/public/functions/formatcounttagbarcode.sql
foundation-database/public/functions/formatcreditmemonumber.sql
foundation-database/public/functions/formatdate.sql
foundation-database/public/functions/formatdatetime.sql
foundation-database/public/functions/formatextprice.sql
foundation-database/public/functions/formatflitemdescrip.sql
foundation-database/public/functions/formatglaccount.sql
foundation-database/public/functions/formatglaccountlong.sql
foundation-database/public/functions/formatindent.sql
foundation-database/public/functions/formatinterval.sql
foundation-database/public/functions/formatinvcnumber.sql
foundation-database/public/functions/formatitemsitebarcode.sql
foundation-database/public/functions/formatlocationbarcode.sql
foundation-database/public/functions/formatlocationcontentsbarcode.sql
foundation-database/public/functions/formatlocationissuebarcode.sql
foundation-database/public/functions/formatlocationname.sql
foundation-database/public/functions/formatlotserialnumber.sql
foundation-database/public/functions/formatmoney.sql
foundation-database/public/functions/formatnumeric.sql
foundation-database/public/functions/formatperiodname.sql
foundation-database/public/functions/formatplonumber.sql
foundation-database/public/functions/formatprcnt.sql
foundation-database/public/functions/formatprice.sql
foundation-database/public/functions/formatpurchprice.sql
foundation-database/public/functions/formatqty.sql
foundation-database/public/functions/formatqtyper.sql
foundation-database/public/functions/formatratio.sql
foundation-database/public/functions/formatrevnumber.sql
foundation-database/public/functions/formatsalesprice.sql
foundation-database/public/functions/formatscrap.sql
foundation-database/public/functions/formatshipmentnumber.sql
foundation-database/public/functions/formatsobarcode.sql
foundation-database/public/functions/formatsoitembarcode.sql
foundation-database/public/functions/formatsoitemnumber.sql
foundation-database/public/functions/formatsolinenumber.sql
foundation-database/public/functions/formatsonumber.sql
foundation-database/public/functions/formattime.sql
foundation-database/public/functions/formatuomratio.sql
foundation-database/public/functions/formatuserbarcode.sql
foundation-database/public/functions/formatweight.sql
foundation-database/public/functions/formatwobarcode.sql
foundation-database/public/functions/formatwonumber.sql
foundation-database/public/functions/formatwooperseq.sql
foundation-database/public/functions/forwardupdateaccount.sql
foundation-database/public/functions/forwardupdateinvbalance.sql
foundation-database/public/functions/forwardupdateitemsite.sql
foundation-database/public/functions/forwardupdatetrialbalance.sql
foundation-database/public/functions/freezeaccountingperiod.sql
foundation-database/public/functions/freightdetail.sql
foundation-database/public/functions/freightdetailquote.sql
foundation-database/public/functions/freightforrecv.sql
foundation-database/public/functions/getactiverevid.sql
foundation-database/public/functions/getaddrid.sql
foundation-database/public/functions/getadjustmenttaxtypeid.sql
foundation-database/public/functions/getaropenid.sql
foundation-database/public/functions/getbankaccntid.sql
foundation-database/public/functions/getbomitemid.sql
foundation-database/public/functions/getbooitemseqid.sql
foundation-database/public/functions/getbudgheadid.sql
foundation-database/public/functions/getcashrcptid.sql
foundation-database/public/functions/getcharid.sql
foundation-database/public/functions/getclasscodeid.sql
foundation-database/public/functions/getcmheadid.sql
foundation-database/public/functions/getcmnttypeid.sql
foundation-database/public/functions/getcntctid.sql
foundation-database/public/functions/getcoheadid.sql
foundation-database/public/functions/getcoitemid.sql
foundation-database/public/functions/getcontrcteffective.sql
foundation-database/public/functions/getcontrctexpires.sql
foundation-database/public/functions/getcontrctid.sql
foundation-database/public/functions/getcostcatid.sql
foundation-database/public/functions/getcostelemid.sql
foundation-database/public/functions/getcrmacctid.sql
foundation-database/public/functions/getcurrid.sql
foundation-database/public/functions/getcustid.sql
foundation-database/public/functions/getcustnamefrominfo.sql
foundation-database/public/functions/getcusttypeid.sql
foundation-database/public/functions/getdeptid.sql
foundation-database/public/functions/getediprofileid.sql
foundation-database/public/functions/getediprofilename.sql
foundation-database/public/functions/geteffectivextuser.sql
foundation-database/public/functions/getempid.sql
foundation-database/public/functions/getexpcatid.sql
foundation-database/public/functions/getflcoldata.sql
foundation-database/public/functions/getflstmthead.sql
foundation-database/public/functions/getfltrendhead.sql
foundation-database/public/functions/getfreightclassid.sql
foundation-database/public/functions/getfreighttaxtypeid.sql
foundation-database/public/functions/getgainlossaccntid.sql
foundation-database/public/functions/getglaccntid.sql
foundation-database/public/functions/getimageid.sql
foundation-database/public/functions/getincdtcatid.sql
foundation-database/public/functions/getincdtcrmacctid.sql
foundation-database/public/functions/getincdtpriorityid.sql
foundation-database/public/functions/getincdtresolutionid.sql
foundation-database/public/functions/getincdtseverityid.sql
foundation-database/public/functions/getincidentid.sql
foundation-database/public/functions/getinvcheadid.sql
foundation-database/public/functions/getinvcitemlotserial.sql
foundation-database/public/functions/getipsheadid.sql
foundation-database/public/functions/getipsitemid.sql
foundation-database/public/functions/getipsprodcatid.sql
foundation-database/public/functions/getitemid.sql
foundation-database/public/functions/getitemidfromupc.sql
foundation-database/public/functions/getitemsiteid.sql
foundation-database/public/functions/getitemsrcid.sql
foundation-database/public/functions/getitemtaxtype.sql
foundation-database/public/functions/getlasttrialbalid.sql
foundation-database/public/functions/getlocationid.sql
foundation-database/public/functions/getlotserialid.sql
foundation-database/public/functions/getopenshipment.sql [new file with mode: 0644]
foundation-database/public/functions/getopheadid.sql
foundation-database/public/functions/getpacklistcharname.sql
foundation-database/public/functions/getpacklistcharvalue.sql
foundation-database/public/functions/getpacklistitemlotserial.sql
foundation-database/public/functions/getperiodid.sql
foundation-database/public/functions/getpkgheadid.sql
foundation-database/public/functions/getplancodeid.sql
foundation-database/public/functions/getpoheadid.sql
foundation-database/public/functions/getpoitemid.sql
foundation-database/public/functions/getprjaccntid.sql
foundation-database/public/functions/getprjid.sql
foundation-database/public/functions/getprjtaskid.sql
foundation-database/public/functions/getprodcatid.sql
foundation-database/public/functions/getprospectid.sql
foundation-database/public/functions/getquoteid.sql
foundation-database/public/functions/getquotelineitemid.sql
foundation-database/public/functions/getquotescheddate.sql [new file with mode: 0644]
foundation-database/public/functions/getrevid.sql
foundation-database/public/functions/getrsnid.sql
foundation-database/public/functions/getsalescatid.sql
foundation-database/public/functions/getsaleslineitemid.sql
foundation-database/public/functions/getsalesorderid.sql
foundation-database/public/functions/getsalesrepid.sql
foundation-database/public/functions/getsaletypeid.sql
foundation-database/public/functions/getshiftid.sql
foundation-database/public/functions/getshipchrgid.sql
foundation-database/public/functions/getshipformid.sql
foundation-database/public/functions/getshipheadid.sql
foundation-database/public/functions/getshiptoid.sql
foundation-database/public/functions/getshiptonumberfrominfo.sql
foundation-database/public/functions/getshipviaid.sql
foundation-database/public/functions/getshipzoneid.sql
foundation-database/public/functions/getsitetypeid.sql
foundation-database/public/functions/getsoitemstatus.sql [new file with mode: 0644]
foundation-database/public/functions/getsoscheddate.sql
foundation-database/public/functions/getsostatus.sql
foundation-database/public/functions/getsubtax.sql
foundation-database/public/functions/gettaxauthid.sql
foundation-database/public/functions/gettaxid.sql
foundation-database/public/functions/gettaxtypeid.sql
foundation-database/public/functions/gettaxzoneid.sql
foundation-database/public/functions/gettermsid.sql
foundation-database/public/functions/getunassignedaccntid.sql
foundation-database/public/functions/getuomid.sql
foundation-database/public/functions/getuomtypeid.sql
foundation-database/public/functions/getusrid.sql
foundation-database/public/functions/getusrlocaleid.sql
foundation-database/public/functions/getvendaddrid.sql
foundation-database/public/functions/getvendid.sql
foundation-database/public/functions/getvendtypeid.sql
foundation-database/public/functions/getwarehousid.sql
foundation-database/public/functions/getwhsezoneid.sql
foundation-database/public/functions/grantallmodulecmnttypesource.sql
foundation-database/public/functions/grantallmodulepriv.sql
foundation-database/public/functions/grantallmoduleprivgroup.sql
foundation-database/public/functions/grantcmnttypesource.sql
foundation-database/public/functions/grantgroup.sql
foundation-database/public/functions/grantpriv.sql
foundation-database/public/functions/grantprivgroup.sql
foundation-database/public/functions/hasalarms.sql
foundation-database/public/functions/hasevents.sql
foundation-database/public/functions/hasmessages.sql
foundation-database/public/functions/haspriv.sql
foundation-database/public/functions/hasprivonobject.sql
foundation-database/public/functions/implodewo.sql
foundation-database/public/functions/incdt.sql
foundation-database/public/functions/indentedbom.sql
foundation-database/public/functions/indentedwhereused.sql
foundation-database/public/functions/indentedwo.sql
foundation-database/public/functions/indentedwomatl.sql
foundation-database/public/functions/initeffectivextuser.sql
foundation-database/public/functions/initialdistribution.sql
foundation-database/public/functions/insertIntoGLSeries.sql
foundation-database/public/functions/insertccard.sql
foundation-database/public/functions/insertflgroup.sql
foundation-database/public/functions/insertgltransaction.sql
foundation-database/public/functions/insertitemcost.sql
foundation-database/public/functions/intervaltominutes.sql
foundation-database/public/functions/invadjustment.sql
foundation-database/public/functions/invexpense.sql
foundation-database/public/functions/invhistsense.sql
foundation-database/public/functions/invoicetotal.sql
foundation-database/public/functions/invreceipt.sql
foundation-database/public/functions/invscrap.sql
foundation-database/public/functions/ismulticurr.sql
foundation-database/public/functions/isnumeric.sql
foundation-database/public/functions/issueallbalancetoshipping.sql
foundation-database/public/functions/issuelinebalancetoshipping.sql
foundation-database/public/functions/issues.sql
foundation-database/public/functions/issuetoshipping.sql
foundation-database/public/functions/issuewomaterial.sql
foundation-database/public/functions/issuewomaterialbatch.sql
foundation-database/public/functions/itemaltcapinvrat.sql
foundation-database/public/functions/itemaltcapuom.sql
foundation-database/public/functions/itemcapinvrat.sql
foundation-database/public/functions/itemcapuom.sql
foundation-database/public/functions/itemcharprice.sql
foundation-database/public/functions/itemcharvalue.sql
foundation-database/public/functions/itemcost.sql
foundation-database/public/functions/iteminventoryuominuse.sql
foundation-database/public/functions/iteminvpricerat.sql
foundation-database/public/functions/itemipsprice.sql
foundation-database/public/functions/itemlocdistqty.sql
foundation-database/public/functions/itemprice.sql
foundation-database/public/functions/itemsellinguom.sql
foundation-database/public/functions/itemsrcprice.sql
foundation-database/public/functions/itemuombytype.sql
foundation-database/public/functions/itemuomfractionalbytype.sql
foundation-database/public/functions/itemuomfractionalbyuom.sql
foundation-database/public/functions/itemuomratiobytype.sql
foundation-database/public/functions/itemuomtouom.sql
foundation-database/public/functions/itemuomtouomratio.sql
foundation-database/public/functions/login.sql
foundation-database/public/functions/logout.sql
foundation-database/public/functions/lowercost.sql
foundation-database/public/functions/maintainbomworkspace.sql
foundation-database/public/functions/markapcheckasposted.sql
foundation-database/public/functions/markapcheckasprinted.sql
foundation-database/public/functions/markcheckasposted.sql
foundation-database/public/functions/markcheckasprinted.sql
foundation-database/public/functions/massexpirebomitem.sql
foundation-database/public/functions/massreplacebomitem.sql
foundation-database/public/functions/merge2crmaccts.sql
foundation-database/public/functions/mergecrmaccts.sql
foundation-database/public/functions/movebomitemdown.sql
foundation-database/public/functions/movebomitemup.sql
foundation-database/public/functions/moveccarddown.sql
foundation-database/public/functions/moveccardup.sql
foundation-database/public/functions/moveflgroupdown.sql
foundation-database/public/functions/moveflgroupup.sql
foundation-database/public/functions/moveflitemdown.sql
foundation-database/public/functions/moveflitemup.sql
foundation-database/public/functions/moveflspecdown.sql
foundation-database/public/functions/moveflspecup.sql
foundation-database/public/functions/movescript.sql
foundation-database/public/functions/moveuiform.sql
foundation-database/public/functions/nextperiodbyinterval.sql
foundation-database/public/functions/nextprsubnumber.sql
foundation-database/public/functions/nextwosubnumber.sql
foundation-database/public/functions/noneg.sql
foundation-database/public/functions/nopos.sql
foundation-database/public/functions/normalizetrialbal.sql
foundation-database/public/functions/numofdatabaseusers.sql
foundation-database/public/functions/numofserverusers.sql
foundation-database/public/functions/openaccountingperiod.sql
foundation-database/public/functions/openaccountingyearperiod.sql
foundation-database/public/functions/openapitemsvalue.sql
foundation-database/public/functions/openaritemsvalue.sql
foundation-database/public/functions/openrecurringitems.sql
foundation-database/public/functions/ophead.sql
foundation-database/public/functions/orderedbypo.sql
foundation-database/public/functions/orderedbywo.sql
foundation-database/public/functions/orderhead.sql
foundation-database/public/functions/orderitem.sql
foundation-database/public/functions/orderitemdata.sql
foundation-database/public/functions/packageisenabled.sql
foundation-database/public/functions/pkgmaybemodified.sql
foundation-database/public/functions/postapcheck.sql
foundation-database/public/functions/postapchecks.sql
foundation-database/public/functions/postapcreditmemoapplication.sql
foundation-database/public/functions/postapopenitems.sql
foundation-database/public/functions/postarcreditmemoapplication.sql
foundation-database/public/functions/postaropenitems.sql
foundation-database/public/functions/postbankadjustment.sql
foundation-database/public/functions/postbankreconciliation.sql
foundation-database/public/functions/postbillingselection.sql
foundation-database/public/functions/postbillingselectionconsolidated.sql
foundation-database/public/functions/postbillingselections.sql
foundation-database/public/functions/postcashreceipt.sql
foundation-database/public/functions/postcashreceiptdisc.sql
foundation-database/public/functions/postcccashreceipt.sql
foundation-database/public/functions/postcccredit.sql
foundation-database/public/functions/postccvoid.sql
foundation-database/public/functions/postcheck.sql
foundation-database/public/functions/postchecks.sql
foundation-database/public/functions/postcomment.sql
foundation-database/public/functions/postcost.sql
foundation-database/public/functions/postcountslip.sql
foundation-database/public/functions/postcounttag.sql
foundation-database/public/functions/postcounttaglocation.sql
foundation-database/public/functions/postcounttags.sql
foundation-database/public/functions/postcreditmemo.sql
foundation-database/public/functions/postcreditmemos.sql
foundation-database/public/functions/postevent.sql [new file with mode: 0644]
foundation-database/public/functions/postglseries.sql
foundation-database/public/functions/postglseriesnosumm.sql
foundation-database/public/functions/postintoinvbalance.sql
foundation-database/public/functions/postintotrialbalance.sql
foundation-database/public/functions/postinvhist.sql
foundation-database/public/functions/postinvoice.sql
foundation-database/public/functions/postinvoices.sql
foundation-database/public/functions/postinvtrans.sql
foundation-database/public/functions/postitemlocseries.sql
foundation-database/public/functions/postjournals.sql
foundation-database/public/functions/postmessage.sql
foundation-database/public/functions/postmisccount.sql
foundation-database/public/functions/postpogltransactions.sql
foundation-database/public/functions/postporeceipt.sql
foundation-database/public/functions/postporeceipts.sql
foundation-database/public/functions/postporeturncreditmemo.sql
foundation-database/public/functions/postporeturns.sql
foundation-database/public/functions/postproduction.sql
foundation-database/public/functions/postreceipt.sql
foundation-database/public/functions/postreceipts.sql
foundation-database/public/functions/postsogltransactions.sql
foundation-database/public/functions/postsoitemproduction.sql
foundation-database/public/functions/poststandardjournal.sql
foundation-database/public/functions/poststandardjournalgroup.sql
foundation-database/public/functions/postvalueintoinvbalance.sql
foundation-database/public/functions/postvoucher.sql
foundation-database/public/functions/postvouchers.sql
foundation-database/public/functions/primarykeyfields.sql
foundation-database/public/functions/prj.sql
foundation-database/public/functions/prjtask.sql
foundation-database/public/functions/purgecreditmemos.sql
foundation-database/public/functions/purgecrmacctmerge.sql
foundation-database/public/functions/purgeinvoicerecord.sql
foundation-database/public/functions/purgeinvoicerecords.sql
foundation-database/public/functions/purgepostedcountslips.sql
foundation-database/public/functions/purgepostedcounttags.sql
foundation-database/public/functions/purgeshipments.sql
foundation-database/public/functions/qtyallocated.sql
foundation-database/public/functions/qtyatshipping.sql
foundation-database/public/functions/qtyavailable.sql
foundation-database/public/functions/qtyinshipment.sql
foundation-database/public/functions/qtylocation.sql
foundation-database/public/functions/qtyordered.sql
foundation-database/public/functions/qtypr.sql
foundation-database/public/functions/qtyreserved.sql [new file with mode: 0644]
foundation-database/public/functions/qtytoreceive.sql
foundation-database/public/functions/recallshipment.sql
foundation-database/public/functions/recallwo.sql
foundation-database/public/functions/receipts.sql
foundation-database/public/functions/releaseapmemonumber.sql
foundation-database/public/functions/releasearmemonumber.sql
foundation-database/public/functions/releasecashrcptnumber.sql
foundation-database/public/functions/releasecmnumber.sql
foundation-database/public/functions/releasecrmaccountnumber.sql
foundation-database/public/functions/releaseincidentnumber.sql
foundation-database/public/functions/releaseinvcnumber.sql
foundation-database/public/functions/releasenumber.sql
foundation-database/public/functions/releaseponumber.sql
foundation-database/public/functions/releaseprnumber.sql
foundation-database/public/functions/releasepurchaseorder.sql
foundation-database/public/functions/releasequnumber.sql
foundation-database/public/functions/releaseshipmentnumber.sql
foundation-database/public/functions/releasesohead.sql
foundation-database/public/functions/releasesonumber.sql
foundation-database/public/functions/releaseunusedbillingheader.sql
foundation-database/public/functions/releasevonumber.sql
foundation-database/public/functions/releasewo.sql
foundation-database/public/functions/releasewonumber.sql
foundation-database/public/functions/relocateinventory.sql
foundation-database/public/functions/reopenbankreconciliation.sql [new file with mode: 0644]
foundation-database/public/functions/reorderdate.sql
foundation-database/public/functions/replaceallvoidedapchecks.sql
foundation-database/public/functions/replaceallvoidedchecks.sql
foundation-database/public/functions/replacevoidedapcheck.sql
foundation-database/public/functions/replacevoidedcheck.sql
foundation-database/public/functions/reprioritizewo.sql
foundation-database/public/functions/resetdbobjperms.sql
foundation-database/public/functions/resetlowlevelcode.sql
foundation-database/public/functions/resetqohbalance.sql
foundation-database/public/functions/resolvecosaccount.sql
foundation-database/public/functions/resolvecowaccount.sql
foundation-database/public/functions/resolvecreditaccount.sql
foundation-database/public/functions/resolvesalesaccount.sql
foundation-database/public/functions/restoresaleshistory.sql
foundation-database/public/functions/returncompleteshipment.sql
foundation-database/public/functions/returnitemshipments.sql
foundation-database/public/functions/returnshipmenttransaction.sql
foundation-database/public/functions/returnwomaterial.sql
foundation-database/public/functions/returnwomaterialbatch.sql
foundation-database/public/functions/reversecashreceipt.sql
foundation-database/public/functions/reversecashreceiptdisc.sql
foundation-database/public/functions/reverseglseries.sql
foundation-database/public/functions/revokeallmodulecmnttypesource.sql
foundation-database/public/functions/revokeallmodulepriv.sql
foundation-database/public/functions/revokeallmoduleprivgroup.sql
foundation-database/public/functions/revokecmnttypesource.sql
foundation-database/public/functions/revokegroup.sql
foundation-database/public/functions/revokepriv.sql
foundation-database/public/functions/revokeprivgroup.sql
foundation-database/public/functions/rollupactualcost.sql
foundation-database/public/functions/rollupsoracost.sql
foundation-database/public/functions/rollupstandardcost.sql
foundation-database/public/functions/roundcost.sql
foundation-database/public/functions/roundlocale.sql
foundation-database/public/functions/roundqty.sql
foundation-database/public/functions/roundsale.sql
foundation-database/public/functions/roundup.sql
foundation-database/public/functions/saveaddr.sql
foundation-database/public/functions/savealarm.sql
foundation-database/public/functions/savebomhead.sql
foundation-database/public/functions/savecntct.sql
foundation-database/public/functions/saveimageass.sql
foundation-database/public/functions/saveipsitem.sql
foundation-database/public/functions/saveipsprodcat.sql
foundation-database/public/functions/saveitemimage.sql
foundation-database/public/functions/saveitemuomconv.sql
foundation-database/public/functions/savemetasql.sql
foundation-database/public/functions/scraps.sql
foundation-database/public/functions/scrapwomaterial.sql
foundation-database/public/functions/selectbalanceforbilling.sql
foundation-database/public/functions/selectdiscountitemsforpayment.sql
foundation-database/public/functions/selectdueitemsforpayment.sql
foundation-database/public/functions/selectforbilling.sql
foundation-database/public/functions/selectpayment.sql
foundation-database/public/functions/selectuninvoicedshipment.sql
foundation-database/public/functions/selectuninvoicedshipments.sql
foundation-database/public/functions/setapjournalnumber.sql
foundation-database/public/functions/setarjournalnumber.sql
foundation-database/public/functions/setbudget.sql
foundation-database/public/functions/setbytea.sql
foundation-database/public/functions/setccbankaccnt.sql
foundation-database/public/functions/seteffectivextuser.sql
foundation-database/public/functions/setgljournalnumber.sql
foundation-database/public/functions/setmetric.sql
foundation-database/public/functions/setmetricenc.sql
foundation-database/public/functions/setnextapmemonumber.sql
foundation-database/public/functions/setnextarmemonumber.sql
foundation-database/public/functions/setnextcashrcptnumber.sql
foundation-database/public/functions/setnextchecknumber.sql
foundation-database/public/functions/setnextcmnumber.sql
foundation-database/public/functions/setnextcrmaccountnumber.sql
foundation-database/public/functions/setnextincidentnumber.sql
foundation-database/public/functions/setnextinvcnumber.sql
foundation-database/public/functions/setnextnumber.sql
foundation-database/public/functions/setnextponumber.sql
foundation-database/public/functions/setnextprnumber.sql
foundation-database/public/functions/setnextqunumber.sql
foundation-database/public/functions/setnextshipmentnumber.sql
foundation-database/public/functions/setnextsonumber.sql
foundation-database/public/functions/setnextvcnumber.sql
foundation-database/public/functions/setnextwonumber.sql
foundation-database/public/functions/setusercancreateusers.sql
foundation-database/public/functions/setuserpreference.sql
foundation-database/public/functions/shipments.sql
foundation-database/public/functions/shipshipment.sql
foundation-database/public/functions/singlecharacteristicstostring.sql
foundation-database/public/functions/singlelevelbom.sql
foundation-database/public/functions/site.sql
foundation-database/public/functions/snoozemessage.sql
foundation-database/public/functions/spellamount.sql
foundation-database/public/functions/splitreceipt.sql
foundation-database/public/functions/splitrecurrence.sql
foundation-database/public/functions/startoftime.sql
foundation-database/public/functions/stdcost.sql
foundation-database/public/functions/sufficientinventorytoshipitem.sql
foundation-database/public/functions/sufficientinventorytoshiporder.sql
foundation-database/public/functions/summarizedbom.sql
foundation-database/public/functions/summarizetransactions.sql
foundation-database/public/functions/summdemand.sql
foundation-database/public/functions/summprod.sql
foundation-database/public/functions/summtransa.sql
foundation-database/public/functions/summtransc.sql
foundation-database/public/functions/summtransi.sql
foundation-database/public/functions/summtransr.sql
foundation-database/public/functions/summtranss.sql
foundation-database/public/functions/summtranst.sql
foundation-database/public/functions/taxassignments.sql
foundation-database/public/functions/thawaccountingperiod.sql
foundation-database/public/functions/thawitemsite.sql
foundation-database/public/functions/todoitem.sql
foundation-database/public/functions/todoitemmove.sql
foundation-database/public/functions/todoitemmovedown.sql
foundation-database/public/functions/todoitemmoveup.sql
foundation-database/public/functions/togglebankreccleared.sql
foundation-database/public/functions/togglebomitemcost.sql
foundation-database/public/functions/tonumeric.sql
foundation-database/public/functions/transitwhs.sql
foundation-database/public/functions/transtype.sql
foundation-database/public/functions/trylock.sql
foundation-database/public/functions/undomerge.sql
foundation-database/public/functions/unreleasepurchaseorder.sql [new file with mode: 0644]
foundation-database/public/functions/uomusedforitem.sql
foundation-database/public/functions/updateabcclass.sql
foundation-database/public/functions/updatecharassignment.sql
foundation-database/public/functions/updatecost.sql
foundation-database/public/functions/updatecustomprivs.sql
foundation-database/public/functions/updateitemcost.sql
foundation-database/public/functions/updateitemsiteleadtime.sql
foundation-database/public/functions/updatelistprice.sql
foundation-database/public/functions/updatelowerusercosts.sql
foundation-database/public/functions/updatelowlevel.sql
foundation-database/public/functions/updateoutlevel.sql
foundation-database/public/functions/updatereorderlevel.sql
foundation-database/public/functions/updateretainedearnings.sql
foundation-database/public/functions/updatesoracost.sql
foundation-database/public/functions/updatestdcost.sql
foundation-database/public/functions/updatetodoitem.sql
foundation-database/public/functions/usedefaultlocation.sql
foundation-database/public/functions/usercancreateusers.sql
foundation-database/public/functions/usercanlogin.sql
foundation-database/public/functions/userid.sql
foundation-database/public/functions/validateorderqty.sql
foundation-database/public/functions/validlocation.sql
foundation-database/public/functions/valueatshipping.sql
foundation-database/public/functions/voidapcheck.sql
foundation-database/public/functions/voidapopenvoucher.sql
foundation-database/public/functions/voidcheck.sql
foundation-database/public/functions/voidcreditmemo.sql
foundation-database/public/functions/voidinvoice.sql
foundation-database/public/functions/voidpostedapcheck.sql
foundation-database/public/functions/voidpostedcheck.sql
foundation-database/public/functions/woeffectivedate.sql
foundation-database/public/functions/woinvavail.sql
foundation-database/public/functions/woinvavailmatl.sql
foundation-database/public/functions/wostarted.sql
foundation-database/public/tables/metasql/accountNumbers-detail.mql
foundation-database/public/tables/metasql/addresses-detail.mql
foundation-database/public/tables/metasql/allocations-detail.mql
foundation-database/public/tables/metasql/apAging-detail.mql
foundation-database/public/tables/metasql/apApplications-detail.mql
foundation-database/public/tables/metasql/apOpenItems-detail.mql
foundation-database/public/tables/metasql/apOpenItems-selectedpayments.mql
foundation-database/public/tables/metasql/apOpenItems-selectpayments.mql
foundation-database/public/tables/metasql/arAging-detail.mql
foundation-database/public/tables/metasql/arApplications-detail.mql
foundation-database/public/tables/metasql/arHistory-detail.mql
foundation-database/public/tables/metasql/arOpenApplications-detail.mql
foundation-database/public/tables/metasql/arOpenItems-detail.mql
foundation-database/public/tables/metasql/arOpenItems-f_detail.mql
foundation-database/public/tables/metasql/assessFinanceCharges-detail.mql [new file with mode: 0644]
foundation-database/public/tables/metasql/backlog-detail.mql
foundation-database/public/tables/metasql/bankrec-checks.mql
foundation-database/public/tables/metasql/bankrec-clearedbalance.mql
foundation-database/public/tables/metasql/bankrec-receipts.mql
foundation-database/public/tables/metasql/bankrecHistory-reconciled.mql
foundation-database/public/tables/metasql/bankrecHistory-unreconciled.mql
foundation-database/public/tables/metasql/billingSelections-detail.mql
foundation-database/public/tables/metasql/bom-detail.mql
foundation-database/public/tables/metasql/bomItems-detail.mql
foundation-database/public/tables/metasql/bookings-detail.mql
foundation-database/public/tables/metasql/briefEarnedCommission-detail.mql
foundation-database/public/tables/metasql/briefSalesHistory-detail.mql
foundation-database/public/tables/metasql/capacityUOMs-detail.mql
foundation-database/public/tables/metasql/cashReceipts-detail.mql
foundation-database/public/tables/metasql/ccpayments.mql
foundation-database/public/tables/metasql/charass-populate.mql
foundation-database/public/tables/metasql/checkRegister-detail.mql
foundation-database/public/tables/metasql/checks-detail.mql
foundation-database/public/tables/metasql/contact-muststayactive.mql
foundation-database/public/tables/metasql/contact-uses.mql
foundation-database/public/tables/metasql/contactmerge-contactused.mql
foundation-database/public/tables/metasql/contactmerge-delete.mql
foundation-database/public/tables/metasql/contactmerge-deselect.mql
foundation-database/public/tables/metasql/contactmerge-merge.mql
foundation-database/public/tables/metasql/contactmerge-merged.mql
foundation-database/public/tables/metasql/contactmerge-populate.mql
foundation-database/public/tables/metasql/contactmerge-purge.mql
foundation-database/public/tables/metasql/contactmerge-restore.mql
foundation-database/public/tables/metasql/contactmerge-search.mql
foundation-database/public/tables/metasql/contactmerge-select.mql
foundation-database/public/tables/metasql/contactmerge-selectcol.mql
foundation-database/public/tables/metasql/contacts-detail.mql
foundation-database/public/tables/metasql/contract-itemsources.mql [new file with mode: 0644]
foundation-database/public/tables/metasql/contracts-detail.mql
foundation-database/public/tables/metasql/costedBOM-detail.mql
foundation-database/public/tables/metasql/costelem_unusedbyitem.mql
foundation-database/public/tables/metasql/countSlip-detail.mql
foundation-database/public/tables/metasql/countTag-detail.mql
foundation-database/public/tables/metasql/countTags-create.mql
foundation-database/public/tables/metasql/countTags-detail.mql
foundation-database/public/tables/metasql/creditCards-detail.mql
foundation-database/public/tables/metasql/creditMemo-editlist.mql
foundation-database/public/tables/metasql/creditMemoCreditCards-detail.mql
foundation-database/public/tables/metasql/crm_strictcountrycheck.mql
foundation-database/public/tables/metasql/crmaccountmerge-pickdatasources.mql
foundation-database/public/tables/metasql/crmaccountmerge-wip.mql
foundation-database/public/tables/metasql/crmaccounts-detail.mql
foundation-database/public/tables/metasql/currencyConversions-detail.mql
foundation-database/public/tables/metasql/customers-detail.mql
foundation-database/public/tables/metasql/customers-statement.mql
foundation-database/public/tables/metasql/depositesRegister-detail.mql
foundation-database/public/tables/metasql/detailedInventoryHistory-detail.mql
foundation-database/public/tables/metasql/distributeInventory-locations.mql
foundation-database/public/tables/metasql/employees-detail.mql
foundation-database/public/tables/metasql/events-detail.mql
foundation-database/public/tables/metasql/expiredInventory-detail.mql
foundation-database/public/tables/metasql/freightPrices-detail.mql
foundation-database/public/tables/metasql/frozenItemSites-detail.mql
foundation-database/public/tables/metasql/glseries-checkeditable.mql
foundation-database/public/tables/metasql/glseries-detail.mql
foundation-database/public/tables/metasql/glseries-postjournal.mql
foundation-database/public/tables/metasql/gltransactions-detail.mql
foundation-database/public/tables/metasql/incidents-detail.mql
foundation-database/public/tables/metasql/invalidBillsofMaterials-detail.mql
foundation-database/public/tables/metasql/inventoryAvailability-byCustOrSO.mql
foundation-database/public/tables/metasql/inventoryAvailability-general.mql
foundation-database/public/tables/metasql/inventoryAvailabilitybyWorkorder-detail.mql
foundation-database/public/tables/metasql/inventoryHistory-detail.mql
foundation-database/public/tables/metasql/inventoryLocator-detail.mql
foundation-database/public/tables/metasql/invoiceInformation-detail.mql
foundation-database/public/tables/metasql/invoiceRegister-detail.mql
foundation-database/public/tables/metasql/invoices-detail.mql
foundation-database/public/tables/metasql/invoices-print.mql
foundation-database/public/tables/metasql/issueToShipping-detail.mql
foundation-database/public/tables/metasql/itemCost-detail.mql
foundation-database/public/tables/metasql/itemCost-list.mql
foundation-database/public/tables/metasql/itemPricingSchedule-detail.mql
foundation-database/public/tables/metasql/itemReceipt-populateEdit.mql
foundation-database/public/tables/metasql/itemReceipt-populateNew.mql
foundation-database/public/tables/metasql/itemReceipt-sourceItemSite.mql
foundation-database/public/tables/metasql/itemSites-detail.mql
foundation-database/public/tables/metasql/itemSources-detail.mql
foundation-database/public/tables/metasql/itemSources-prices.mql
foundation-database/public/tables/metasql/itemSources-search.mql
foundation-database/public/tables/metasql/itemcostdetail_detail.mql
foundation-database/public/tables/metasql/items-detail.mql
foundation-database/public/tables/metasql/itemsWithoutItemSources-detail.mql
foundation-database/public/tables/metasql/journals-detail.mql
foundation-database/public/tables/metasql/maintainShipping-detail.mql
foundation-database/public/tables/metasql/manufacture-jobcosting.mql
foundation-database/public/tables/metasql/metasqls-detail.mql
foundation-database/public/tables/metasql/mrpDetail-detail.mql
foundation-database/public/tables/metasql/mrpDetail-item.mql
foundation-database/public/tables/metasql/openVouchers-populate.mql
foundation-database/public/tables/metasql/openpurchaseorders-detail.mql
foundation-database/public/tables/metasql/opensalesorders-detail.mql
foundation-database/public/tables/metasql/opportunities-detail.mql
foundation-database/public/tables/metasql/opportunitiesByCRM-detail.mql
foundation-database/public/tables/metasql/orderActivityByProject-detail.mql
foundation-database/public/tables/metasql/orders-detail.mql
foundation-database/public/tables/metasql/package-items.mql
foundation-database/public/tables/metasql/packingList-getreport.mql
foundation-database/public/tables/metasql/packingList-shipment.mql
foundation-database/public/tables/metasql/packingListBatch-clear.mql [new file with mode: 0644]
foundation-database/public/tables/metasql/packingListBatch-detail.mql
foundation-database/public/tables/metasql/packingListBatch-print.mql
foundation-database/public/tables/metasql/packingListBatchByShipVia-print.mql
foundation-database/public/tables/metasql/packingListBatchByShipVia-shipVia.mql
foundation-database/public/tables/metasql/partiallyShippedOrders-detail.mql
foundation-database/public/tables/metasql/pendingAvailability-detail.mql
foundation-database/public/tables/metasql/pendingBOMChanges-detail.mql
foundation-database/public/tables/metasql/poDeliveryDateVariances-detail.mql
foundation-database/public/tables/metasql/poHistory-detail.mql
foundation-database/public/tables/metasql/poItems-detail.mql
foundation-database/public/tables/metasql/poItems-list.mql
foundation-database/public/tables/metasql/poPriceVariances-detail.mql
foundation-database/public/tables/metasql/poReturns-detail.mql
foundation-database/public/tables/metasql/postCountTags-post.mql
foundation-database/public/tables/metasql/postJournals-detail.mql
foundation-database/public/tables/metasql/postJournals-post.mql
foundation-database/public/tables/metasql/pricelist-detail.mql
foundation-database/public/tables/metasql/prices-detail.mql
foundation-database/public/tables/metasql/pricingFreight-detail.mql
foundation-database/public/tables/metasql/projectTasks-detail.mql
foundation-database/public/tables/metasql/projects-detail.mql
foundation-database/public/tables/metasql/projects-detail_nohierarchy.mql [new file with mode: 0644]
foundation-database/public/tables/metasql/prospects-detail.mql
foundation-database/public/tables/metasql/purchase-purchaserequests.mql
foundation-database/public/tables/metasql/purchaseOrderItems-detail.mql
foundation-database/public/tables/metasql/purchaseOrders-detail.mql
foundation-database/public/tables/metasql/qoh-detail.mql
foundation-database/public/tables/metasql/quoteItems-detail.mql
foundation-database/public/tables/metasql/quoteItems-list.mql [new file with mode: 0644]
foundation-database/public/tables/metasql/quotes-detail.mql
foundation-database/public/tables/metasql/receipt-detail.mql
foundation-database/public/tables/metasql/receipt-receiveAll.mql
foundation-database/public/tables/metasql/receivings-detail.mql
foundation-database/public/tables/metasql/reorderExceptionsByPlannerCode-detail.mql
foundation-database/public/tables/metasql/reports-detail.mql
foundation-database/public/tables/metasql/reservations-detail.mql
foundation-database/public/tables/metasql/returnAuthorizations-detail.mql
foundation-database/public/tables/metasql/runningAvailability-detail.mql
foundation-database/public/tables/metasql/salesAccounts-detail.mql
foundation-database/public/tables/metasql/salesHistory-detail.mql
foundation-database/public/tables/metasql/salesOrderItems-detail.mql
foundation-database/public/tables/metasql/salesOrderItems-list.mql
foundation-database/public/tables/metasql/salesOrderStatus-detail.mql
foundation-database/public/tables/metasql/salesOrders-detail.mql
foundation-database/public/tables/metasql/saletype-table.mql
foundation-database/public/tables/metasql/schedule-plannedorders.mql
foundation-database/public/tables/metasql/scripts-detail.mql
foundation-database/public/tables/metasql/selectPayments-applyallcredits.mql
foundation-database/public/tables/metasql/shipments-detail.mql
foundation-database/public/tables/metasql/shippingForm-shipment.mql
foundation-database/public/tables/metasql/slowMovingInventoryByClassCode-detail.mql
foundation-database/public/tables/metasql/standardJournalHistory-detail.mql
foundation-database/public/tables/metasql/substituteAvailability-detail.mql
foundation-database/public/tables/metasql/summarizedBacklogByWarehouse-counts.mql
foundation-database/public/tables/metasql/summarizedBacklogByWarehouse-detail.mql
foundation-database/public/tables/metasql/summarizedBacklogByWarehouse-qtys.mql
foundation-database/public/tables/metasql/summarizedBacklogByWarehouse-totals.mql
foundation-database/public/tables/metasql/summarizedBankrecHistory-detail.mql
foundation-database/public/tables/metasql/summarizedGLTransactions-detail.mql
foundation-database/public/tables/metasql/summarizedSalesHistory-detail.mql
foundation-database/public/tables/metasql/taxAuthorities-detail.mql
foundation-database/public/tables/metasql/taxBreakdown-detail.mql
foundation-database/public/tables/metasql/taxHistory-detail.mql
foundation-database/public/tables/metasql/timePhasedAvailability-detail.mql
foundation-database/public/tables/metasql/timePhasedBookings-detail.mql
foundation-database/public/tables/metasql/timePhasedSales-detail.mql
foundation-database/public/tables/metasql/timePhasedUsageStatisticsByItem-detail.mql
foundation-database/public/tables/metasql/todolist-detail.mql
foundation-database/public/tables/metasql/trialBalances-detail.mql
foundation-database/public/tables/metasql/uiforms-detail.mql
foundation-database/public/tables/metasql/unbalancedQOHByClassCode-detail.mql
foundation-database/public/tables/metasql/undefinedManufacturedItems-detail.mql
foundation-database/public/tables/metasql/uninvoicedReceivings-detail.mql
foundation-database/public/tables/metasql/uninvoicedShipments-detail.mql
foundation-database/public/tables/metasql/unpostedCashReceipts-detail.mql
foundation-database/public/tables/metasql/unpostedReceipts-detail.mql
foundation-database/public/tables/metasql/unusedPurchasedItems-detail.mql
foundation-database/public/tables/metasql/uoms-item.mql
foundation-database/public/tables/metasql/updateListPrices-update.mql
foundation-database/public/tables/metasql/updatePrices-add.mql
foundation-database/public/tables/metasql/updatePrices-availsched.mql
foundation-database/public/tables/metasql/updatePrices-createselsched.mql
foundation-database/public/tables/metasql/updatePrices-dropselsched.mql
foundation-database/public/tables/metasql/updatePrices-remove.mql
foundation-database/public/tables/metasql/updatePrices-selsched.mql
foundation-database/public/tables/metasql/updatePrices-update.mql
foundation-database/public/tables/metasql/updatePrices-updatechar.mql
foundation-database/public/tables/metasql/updateReorderLevels-post.mql
foundation-database/public/tables/metasql/updateReorderLevels-query.mql
foundation-database/public/tables/metasql/updateReorderLevels-update.mql
foundation-database/public/tables/metasql/usageStatistics-detail.mql
foundation-database/public/tables/metasql/validLocationsByItem-detail.mql
foundation-database/public/tables/metasql/vendorAPHistory-detail.mql
foundation-database/public/tables/metasql/vendors-detail.mql
foundation-database/public/tables/metasql/voucher-editlist.mql
foundation-database/public/tables/metasql/voucherItem-distributions.mql
foundation-database/public/tables/metasql/voucherItem-receipts.mql
foundation-database/public/tables/metasql/voucherRegister-detail.mql
foundation-database/public/tables/metasql/whereUsed-detail.mql
foundation-database/public/tables/metasql/workOrderHistory-detail.mql
foundation-database/public/tables/metasql/workOrderMaterial-detail.mql
foundation-database/public/tables/metasql/workOrderSchedule-detail.mql
foundation-database/public/tables/metasql/workOrderSchedule-parameterlist.mql
foundation-database/public/tables/metasql/workOrderVariance-material.mql
foundation-database/public/views/cust.sql
foundation-database/public/views/ipsprice.sql

index 2dc20eb..aeab924 100644 (file)
@@ -6,24 +6,7 @@
     "tables",
     "triggers",
     "types",
-    "remove from 440_schema.sql everything that's defined here. it's now redundant",
-    "public/functions/getaddrid.sql",
-    "public/functions/getcharid.sql",
-    "public/functions/getcntctid.sql",
-    "public/functions/getcrmacctid.sql",
-    "public/functions/getcurrid.sql",
-    "public/functions/getcustid.sql",
-    "public/functions/getimageid.sql",
-    "public/functions/getincdtcatid.sql",
-    "public/functions/getincdtcrmacctid.sql",
-    "public/functions/getincdtpriorityid.sql",
-    "public/functions/getincdtresolutionid.sql",
-    "public/functions/getincdtseverityid.sql",
-    "public/functions/getincidentid.sql",
-    "public/functions/getprjid.sql",
-    "public/functions/getprjtaskid.sql",
-    "public/functions/getusrid.sql",
-    "public/functions/getwarehousid.sql"
+    "remove from 440_schema.sql everything that's defined here. it's now redundant"
   ],
   "databaseScripts": [
     "public/tables/metric.sql",
@@ -72,6 +55,7 @@
     "public/functions/asofinvbal.sql",
     "public/functions/asofinvnn.sql",
     "public/functions/asofinvqty.sql",
+    "public/functions/assessfinancecharge.sql",
     "public/functions/attachcontact.sql",
     "public/functions/attachquotetoopportunity.sql",
     "public/functions/attachsalesordertoopportunity.sql",
@@ -92,6 +76,7 @@
     "public/functions/calcbillingamts.sql",
     "public/functions/calccashbudget.sql",
     "public/functions/calccreditmemoamts.sql",
+    "public/functions/calcinvoiceamt.sql",
     "public/functions/calcpendingarapplications.sql",
     "public/functions/calcquoteamt.sql",
     "public/functions/calcsalesorderamt.sql",
     "public/functions/changeprdate.sql",
     "public/functions/changeprqty.sql",
     "public/functions/changepseudofkeypointers.sql",
+    "public/functions/changepurchasedropship.sql",
     "public/functions/changewodates.sql",
     "public/functions/changewoproject.sql",
     "public/functions/changewoqty.sql",
     "public/functions/freightdetailquote.sql",
     "public/functions/freightforrecv.sql",
     "public/functions/getactiverevid.sql",
+    "public/functions/getaddrid.sql",
     "public/functions/getadjustmenttaxtypeid.sql",
     "public/functions/getaropenid.sql",
     "public/functions/getbankaccntid.sql",
     "public/functions/getbooitemseqid.sql",
     "public/functions/getbudgheadid.sql",
     "public/functions/getcashrcptid.sql",
+    "public/functions/getcharid.sql",
     "public/functions/getclasscodeid.sql",
     "public/functions/getcmheadid.sql",
     "public/functions/getcmnttypeid.sql",
+    "public/functions/getcntctid.sql",
     "public/functions/getcoheadid.sql",
     "public/functions/getcoitemid.sql",
     "public/functions/getcostcatid.sql",
     "public/functions/getcostelemid.sql",
+    "public/functions/getcrmacctid.sql",
+    "public/functions/getcurrid.sql",
     "public/functions/getcustnamefrominfo.sql",
+    "public/functions/getcustid.sql",
     "public/functions/getcusttypeid.sql",
     "public/functions/getdeptid.sql",
     "public/functions/getediprofileid.sql",
     "public/functions/getfreighttaxtypeid.sql",
     "public/functions/getgainlossaccntid.sql",
     "public/functions/getglaccntid.sql",
+    "public/functions/getimageid.sql",
+    "public/functions/getincdtcatid.sql",
+    "public/functions/getincdtcrmacctid.sql",
+    "public/functions/getincdtpriorityid.sql",
+    "public/functions/getincdtresolutionid.sql",
+    "public/functions/getincdtseverityid.sql",
+    "public/functions/getincidentid.sql",
     "public/functions/getinvcheadid.sql",
     "public/functions/getinvcitemlotserial.sql",
     "public/functions/getipsheadid.sql",
     "public/functions/getpacklistitemlotserial.sql",
     "public/functions/getperiodid.sql",
     "public/functions/getpkgheadid.sql",
+    "public/functions/getopenshipment.sql",
     "public/functions/getplancodeid.sql",
     "public/functions/getpoheadid.sql",
     "public/functions/getpoitemid.sql",
     "public/functions/getprjaccntid.sql",
+    "public/functions/getprjid.sql",
+    "public/functions/getprjtaskid.sql",
     "public/functions/getprodcatid.sql",
     "public/functions/getprospectid.sql",
     "public/functions/getquoteid.sql",
+    "public/functions/getquotescheddate.sql",
     "public/functions/getquotelineitemid.sql",
     "public/functions/getrevid.sql",
     "public/functions/getrsnid.sql",
     "public/functions/getshipviaid.sql",
     "public/functions/getshipzoneid.sql",
     "public/functions/getsitetypeid.sql",
+    "public/functions/getsoitemstatus.sql",
     "public/functions/getsoscheddate.sql",
     "public/functions/getsostatus.sql",
     "public/functions/getsubtax.sql",
     "public/functions/getunassignedaccntid.sql",
     "public/functions/getuomid.sql",
     "public/functions/getuomtypeid.sql",
+    "public/functions/getusrid.sql",
     "public/functions/getvendaddrid.sql",
     "public/functions/getvendid.sql",
     "public/functions/getvendtypeid.sql",
+    "public/functions/getwarehousid.sql",
     "public/functions/getwhsezoneid.sql",
     "public/functions/grantallmodulecmnttypesource.sql",
     "public/functions/grantallmodulepriv.sql",
     "public/functions/qtylocation.sql",
     "public/functions/qtyordered.sql",
     "public/functions/qtypr.sql",
+    "public/functions/qtyreserved.sql",
     "public/functions/qtytoreceive.sql",
     "public/functions/recallshipment.sql",
     "public/functions/recallwo.sql",
     "public/functions/releasewo.sql",
     "public/functions/releasewonumber.sql",
     "public/functions/relocateinventory.sql",
+    "public/functions/reopenbankreconciliation.sql",
     "public/functions/reorderdate.sql",
     "public/functions/replaceallvoidedapchecks.sql",
     "public/functions/replaceallvoidedchecks.sql",
     "public/tables/metasql/package-items.mql",
     "public/tables/metasql/packingList-getreport.mql",
     "public/tables/metasql/packingList-shipment.mql",
+    "public/tables/metasql/packingListBatch-clear.mql",
     "public/tables/metasql/packingListBatch-detail.mql",
     "public/tables/metasql/packingListBatch-print.mql",
     "public/tables/metasql/packingListBatchByShipVia-print.mql",
     "public/tables/metasql/purchaseOrders-detail.mql",
     "public/tables/metasql/qoh-detail.mql",
     "public/tables/metasql/quoteItems-detail.mql",
+    "public/tables/metasql/quoteItems-list.mql",
     "public/tables/metasql/quotes-detail.mql",
     "public/tables/metasql/receipt-detail.mql",
     "public/tables/metasql/receipt-receiveAll.mql",
index fd3cb1a..87cfe5e 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION acknowledgeMessage(INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pMsgid ALIAS FOR $1;
index a4d70e9..619eefc 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION actCost(INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN actCost($1, NULL, baseCurrId());
@@ -7,7 +7,7 @@ END;
 ' LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION actCost(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN actCost($1, $2, baseCurrId());
@@ -15,7 +15,7 @@ END;
 ' LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION actCost(INTEGER, INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index d96cdd4..dd77604 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION addrUseCount(integer) RETURNS integer STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pAddrId ALIAS FOR $1;
index 00f472f..cc4773e 100644 (file)
@@ -3,7 +3,7 @@
 --       NULL if there has been an error
 
 CREATE OR REPLACE FUNCTION addTaxToGLSeries(INTEGER, TEXT, TEXT, TEXT, INTEGER, DATE, DATE, TEXT, INTEGER, TEXT) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSequence    ALIAS FOR $1;
index 67725ec..25272ae 100644 (file)
@@ -1,5 +1,5 @@
-CREATE OR REPLACE FUNCTION addToPackingListBatch(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION addToPackingListBatch(INTEGER) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSoheadid    ALIAS FOR $1;
@@ -7,31 +7,31 @@ DECLARE
 BEGIN
 
   -- MIN because error codes are negative
-  SELECT MIN(addToPackingListBatch(''SO'', pSoheadid, shiphead_id)) INTO returnVal
+  SELECT MIN(addToPackingListBatch('SO', pSoheadid, shiphead_id)) INTO returnVal
   FROM shiphead
   WHERE ((shiphead_order_id=pSoheadid)
     AND  (NOT shiphead_shipped)
-    AND  (shiphead_order_type=''SO''));
+    AND  (shiphead_order_type='SO'));
   IF (NOT FOUND OR returnVal IS NULL) THEN
-    returnVal := addToPackingListBatch(''SO'', pSoheadid, NULL);
+    returnVal := addToPackingListBatch('SO', pSoheadid, NULL);
   END IF;
 
   RETURN returnVal;
 END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
 
 
-CREATE OR REPLACE FUNCTION addToPackingListBatch(INTEGER, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION addToPackingListBatch(INTEGER, INTEGER) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
-  RETURN addToPackingListBatch(''SO'', $1, $2);
+  RETURN addToPackingListBatch('SO', $1, $2);
 END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
 
 
-CREATE OR REPLACE FUNCTION addToPackingListBatch(TEXT, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION addToPackingListBatch(TEXT, INTEGER) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pheadtype    ALIAS FOR $1;
@@ -51,11 +51,33 @@ BEGIN
 
   RETURN returnVal;
 END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
 
 
-CREATE OR REPLACE FUNCTION addToPackingListBatch(TEXT, INTEGER, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION addToPackingListBatch(INTEGER, TEXT, INTEGER) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
+-- See www.xtuple.com/CPAL for the full text of the software license.
+DECLARE
+  pwarehousid  ALIAS FOR $1;
+  pheadtype    ALIAS FOR $2;
+  pheadid      ALIAS FOR $3;
+  returnVal    INTEGER;
+BEGIN
+  -- MIN because error codes are negative
+  SELECT MIN(addToPackingListBatch(pheadtype, pheadid,
+                                   getOpenShipmentId(pheadtype, pheadid, pwarehousid))) INTO returnVal;
+
+  IF (NOT FOUND OR returnVal IS NULL) THEN
+    returnVal := addToPackingListBatch(pheadtype, pheadid, NULL);
+  END IF;
+
+  RETURN returnVal;
+END;
+$$ LANGUAGE 'plpgsql';
+
+
+CREATE OR REPLACE FUNCTION addToPackingListBatch(TEXT, INTEGER, INTEGER) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pheadtype    ALIAS FOR $1;
@@ -78,7 +100,7 @@ BEGIN
     VALUES
     ( pheadtype, pheadid, pshipheadid, FALSE );
     -- Auto Firm Sales Orders conditionally based on metric
-    IF ( (pheadtype = ''SO'') AND (fetchMetricBool(''FirmSalesOrderPackingList'')) ) THEN
+    IF ( (pheadtype = 'SO') AND (fetchMetricBool('FirmSalesOrderPackingList')) ) THEN
       UPDATE coitem SET coitem_firm=TRUE
       WHERE (coitem_cohead_id=pheadid);
     END IF; 
@@ -87,4 +109,4 @@ BEGIN
   RETURN pheadid;
 
 END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
index 69de45c..261c4bc 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION adjustInvValue(INTEGER, NUMERIC, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid     ALIAS FOR $1;
index 5336693..ef0e95f 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION adjustments(TEXT) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTransType ALIAS FOR $1;
index b5dee64..9fc7d06 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION allocatedForSo(INTEGER, INTEGER) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
@@ -14,7 +14,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION allocatedForSo(INTEGER, DATE) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
@@ -29,7 +29,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION allocatedForSo(INTEGER, DATE, DATE) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index 975f006..f898525 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION allocatedForWo(INTEGER, INTEGER) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
@@ -14,7 +14,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION allocatedForWo(INTEGER, DATE) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
@@ -29,7 +29,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION allocatedForWo(INTEGER, DATE, DATE) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index 9d476dd..ed21a47 100644 (file)
@@ -1,7 +1,7 @@
 CREATE OR REPLACE FUNCTION alterencrypt(text, text)
   RETURNS integer AS
 '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pOldKey ALIAS FOR $1;
index 5d0028d..3834432 100644 (file)
@@ -1,7 +1,7 @@
 SELECT dropIfExists('FUNCTION', 'apaging(date, boolean)', 'public');
 
 CREATE OR REPLACE FUNCTION apaging(date, boolean) RETURNS SETOF apaging AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pAsOfDate ALIAS FOR $1;
@@ -19,55 +19,61 @@ BEGIN
         --report uses currency rate snapshot to convert all amounts to base based on apopen_docdate to ensure the same exchange rate
 
         --today and greater base:
-        CASE WHEN((apopen_duedate >= DATE(_asOfDate)))
-        THEN (((apopen_amount-apopen_paid+COALESCE(SUM(apapply_target_paid),0)))/apopen_curr_rate *
-        CASE WHEN (apopen_doctype IN ('D', 'V')) THEN 1 ELSE -1 END) ELSE 0 END AS cur_val,
+        CASE WHEN((apopen.apopen_duedate >= DATE(_asOfDate)))
+        THEN (((apopen.apopen_amount - apopen.apopen_paid +
+                COALESCE(SUM(apapply_target_paid * apopen.apopen_curr_rate / target.apopen_curr_rate),0))) / apopen.apopen_curr_rate *
+                CASE WHEN (apopen.apopen_doctype IN ('D', 'V')) THEN 1 ELSE -1 END) ELSE 0 END AS cur_val,
 
         --0 to 30 base
-        CASE WHEN((apopen_duedate >= DATE(_asOfDate)-30) AND (apopen_duedate < DATE(_asOfDate)))
-        THEN (((apopen_amount-apopen_paid+COALESCE(SUM(apapply_target_paid),0)))/apopen_curr_rate *
-        CASE WHEN (apopen_doctype IN ('D', 'V')) THEN 1 ELSE -1 END) ELSE 0 END AS thirty_val,
+        CASE WHEN((apopen.apopen_duedate >= DATE(_asOfDate)-30) AND (apopen.apopen_duedate < DATE(_asOfDate)))
+        THEN (((apopen.apopen_amount - apopen.apopen_paid +
+                COALESCE(SUM(apapply_target_paid * apopen.apopen_curr_rate / target.apopen_curr_rate),0))) / apopen.apopen_curr_rate *
+                CASE WHEN (apopen.apopen_doctype IN ('D', 'V')) THEN 1 ELSE -1 END) ELSE 0 END AS thirty_val,
 
         --30-60 base
-        CASE WHEN((apopen_duedate >= DATE(_asOfDate)-60) AND (apopen_duedate < DATE(_asOfDate) - 30 ))
-        THEN (((apopen_amount-apopen_paid+COALESCE(SUM(apapply_target_paid),0)))/apopen_curr_rate *
-        CASE WHEN (apopen_doctype IN ('D', 'V')) THEN 1 ELSE -1 END) ELSE 0 END AS sixty_val,
+        CASE WHEN((apopen.apopen_duedate >= DATE(_asOfDate)-60) AND (apopen.apopen_duedate < DATE(_asOfDate) - 30 ))
+        THEN (((apopen.apopen_amount - apopen.apopen_paid +
+                COALESCE(SUM(apapply_target_paid * apopen.apopen_curr_rate / target.apopen_curr_rate),0))) / apopen.apopen_curr_rate *
+                CASE WHEN (apopen.apopen_doctype IN ('D', 'V')) THEN 1 ELSE -1 END) ELSE 0 END AS sixty_val,
 
         --60-90 base
-        CASE WHEN((apopen_duedate >= DATE(_asOfDate)-90) AND (apopen_duedate < DATE(_asOfDate) - 60))
-        THEN (((apopen_amount-apopen_paid+COALESCE(SUM(apapply_target_paid),0)))/apopen_curr_rate *
-        CASE WHEN (apopen_doctype IN ('D', 'V')) THEN 1 ELSE -1 END) ELSE 0 END AS ninety_val,
+        CASE WHEN((apopen.apopen_duedate >= DATE(_asOfDate)-90) AND (apopen.apopen_duedate < DATE(_asOfDate) - 60))
+        THEN (((apopen.apopen_amount - apopen.apopen_paid +
+                COALESCE(SUM(apapply_target_paid * apopen.apopen_curr_rate / target.apopen_curr_rate),0))) / apopen.apopen_curr_rate *
+                CASE WHEN (apopen.apopen_doctype IN ('D', 'V')) THEN 1 ELSE -1 END) ELSE 0 END AS ninety_val,
 
         --greater than 90 base:
-        CASE WHEN((apopen_duedate > DATE(_asOfDate)-10000) AND (apopen_duedate < DATE(_asOfDate) - 90))
-        THEN (((apopen_amount-apopen_paid + COALESCE(SUM(apapply_target_paid),0)))/apopen_curr_rate *
-        CASE WHEN (apopen_doctype IN ('D', 'V')) THEN 1 ELSE -1 END) ELSE 0 END AS plus_val,
+        CASE WHEN((apopen.apopen_duedate > DATE(_asOfDate)-10000) AND (apopen.apopen_duedate < DATE(_asOfDate) - 90))
+        THEN (((apopen.apopen_amount - apopen.apopen_paid +
+                COALESCE(SUM(apapply_target_paid * apopen.apopen_curr_rate / target.apopen_curr_rate),0))) / apopen.apopen_curr_rate *
+                CASE WHEN (apopen.apopen_doctype IN ('D', 'V')) THEN 1 ELSE -1 END) ELSE 0 END AS plus_val,
 
         --total amount base:
-        CASE WHEN((apopen_duedate > DATE(_asOfDate)-10000))
-        THEN (((apopen_amount-apopen_paid+COALESCE(SUM(apapply_target_paid),0)))/apopen_curr_rate *
-        CASE WHEN (apopen_doctype IN ('D', 'V')) THEN 1 ELSE -1 END) ELSE 0 END AS total_val,
+        CASE WHEN((apopen.apopen_duedate > DATE(_asOfDate)-10000))
+        THEN (((apopen.apopen_amount - apopen.apopen_paid +
+                COALESCE(SUM(apapply_target_paid * apopen.apopen_curr_rate / target.apopen_curr_rate),0))) / apopen.apopen_curr_rate *
+                CASE WHEN (apopen.apopen_doctype IN ('D', 'V')) THEN 1 ELSE -1 END) ELSE 0 END AS total_val,
 
         --AP Open Amount base
-        CASE WHEN apopen_doctype IN ('C', 'R') 
-        THEN (apopen_amount * -1) / apopen_curr_rate
-        ELSE apopen_amount / apopen_curr_rate END AS apopen_amount,
+        CASE WHEN apopen.apopen_doctype IN ('C', 'R') 
+        THEN (apopen.apopen_amount / apopen.apopen_curr_rate * -1.0)
+        ELSE (apopen.apopen_amount / apopen.apopen_curr_rate) END AS apopen_amount,
         
-        apopen_docdate,
-        apopen_duedate,
-        apopen_ponumber,
-        apopen_invcnumber,
-        apopen_docnumber,
-        apopen_doctype,
+        apopen.apopen_docdate,
+        apopen.apopen_duedate,
+        apopen.apopen_ponumber,
+        apopen.apopen_invcnumber,
+        apopen.apopen_docnumber,
+        apopen.apopen_doctype,
         vend_id,
         vend_name,
         vend_number,
         vend_vendtype_id,
         vendtype_code,
         terms_descrip,
-        determineDiscountDate(terms_id, apopen_docdate) AS discdate,
-        noNeg(apopen_discountable_amount *
-                     CASE WHEN (CURRENT_DATE <= determineDiscountDate(terms_id, apopen_docdate)) THEN terms_discprcnt
+        determineDiscountDate(terms_id, apopen.apopen_docdate) AS discdate,
+        noNeg(apopen.apopen_discountable_amount *
+                     CASE WHEN (CURRENT_DATE <= determineDiscountDate(terms_id, apopen.apopen_docdate)) THEN terms_discprcnt
                      ELSE 0.0 END) AS disc_val,
         terms_discdays AS discdays,
         (terms_discprcnt * 100.0) AS discprcnt
@@ -77,14 +83,16 @@ BEGIN
           LEFT OUTER JOIN apapply ON (((apopen_id=apapply_target_apopen_id)
                                     OR (apopen_id=apapply_source_apopen_id))
                                    AND (apapply_postdate >_asOfDate))
-        WHERE ( (apopen_vend_id = vend_id)
+          LEFT OUTER JOIN apopen target ON (target.apopen_id=apapply_target_apopen_id)
+        WHERE ( (apopen.apopen_vend_id = vend_id)
         AND (vend_vendtype_id=vendtype_id)
-        AND (CASE WHEN (pUseDocDate) THEN apopen_docdate ELSE apopen_distdate END <= _asOfDate)
-        AND (COALESCE(apopen_closedate,_asOfDate+1)>_asOfDate) )
-        GROUP BY apopen_id,apopen_docdate,apopen_duedate,apopen_ponumber, apopen_invcnumber, apopen_docnumber,apopen_doctype,apopen_paid,
-                 apopen_curr_id,apopen_amount,vend_id,vend_name,vend_number,vend_vendtype_id,vendtype_code,terms_descrip,
-                 apopen_curr_rate, terms_id, terms_discdays, terms_discprcnt, apopen_discountable_amount
-        ORDER BY vend_number, apopen_duedate
+        AND (CASE WHEN (pUseDocDate) THEN apopen.apopen_docdate ELSE apopen.apopen_distdate END <= _asOfDate)
+        AND (COALESCE(apopen.apopen_closedate,_asOfDate+1)>_asOfDate) )
+        GROUP BY apopen.apopen_id,apopen.apopen_docdate,apopen.apopen_duedate,apopen.apopen_ponumber,
+                 apopen.apopen_invcnumber,apopen.apopen_docnumber,apopen.apopen_doctype,apopen.apopen_paid,
+                 apopen.apopen_curr_id,apopen.apopen_amount,vend_id,vend_name,vend_number,vend_vendtype_id,vendtype_code,terms_descrip,
+                 apopen.apopen_curr_rate, terms_id, terms_discdays, terms_discprcnt, apopen.apopen_discountable_amount
+        ORDER BY vend_number, apopen.apopen_duedate
   LOOP
         _row.apaging_docdate := _x.apopen_docdate;
         _row.apaging_duedate := _x.apopen_duedate;
index a797231..08c5f84 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION apapplied(INTEGER, DATE) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pApopenid ALIAS FOR $1;
index 9360994..b996bc2 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION apCheckPending(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pApopenid    ALIAS FOR $1;
@@ -12,6 +12,7 @@ BEGIN
    WHERE ((checkitem_apopen_id=pApopenid)
      AND (NOT checkhead_deleted)
      AND (NOT checkhead_replaced)
+     AND (NOT checkhead_void)
      AND (NOT checkhead_posted));
 
   RETURN COALESCE(_qty, 0.0);
index 843c709..cc853b3 100644 (file)
@@ -6,7 +6,7 @@
 -- negative values = a loss.
 CREATE OR REPLACE FUNCTION apcurrGain(INTEGER, INTEGER, NUMERIC, DATE)
 RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pApopenId ALIAS FOR $1;
index 0cb14c2..14395cd 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION applyAPCreditMemoToBalance(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pApopenid ALIAS FOR $1;
index e35c18e..46a2974 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION applyapcredits(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVendId   ALIAS FOR $1;
index 4508c9e..099fe1e 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION applyARCreditMemoToBalance(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pAropenid ALIAS FOR $1;
@@ -13,7 +13,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION applyARCreditMemoToBalance(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSourceAropenid ALIAS FOR $1;
index 4a07ced..4660816 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION applyCashReceiptLineBalance(INTEGER, INTEGER, NUMERIC, INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCashrcptId ALIAS FOR $1;
index 550736b..983224a 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION applyCashReceiptToBalance(INTEGER, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCashrcptid ALIAS FOR $1;
@@ -11,7 +11,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION applyCashReceiptToBalance(INTEGER, NUMERIC, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCashrcptid ALIAS FOR $1;
@@ -26,7 +26,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION applyCashReceiptToBalance(INTEGER, NUMERIC, INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCashrcptid ALIAS FOR $1;
index 8c759be..bb2d400 100644 (file)
@@ -1,6 +1,6 @@
 SELECT dropIfExists('FUNCTION', 'araging(date)', 'public');
 CREATE OR REPLACE FUNCTION araging(date, boolean) RETURNS SETOF araging AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pAsOfDate ALIAS FOR $1;
@@ -20,7 +20,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION araging(date, boolean, boolean) RETURNS SETOF araging AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pAsOfDate ALIAS FOR $1;
index 525a31e..4d608a4 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION arapplied(INTEGER, DATE) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pAropenid ALIAS FOR $1;
index bc76eb9..dcc6730 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION archiveSalesHistory(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSohistid ALIAS FOR $1;
index 071eeb6..037570e 100644 (file)
@@ -6,7 +6,7 @@
 -- negative values = a loss.
 CREATE OR REPLACE FUNCTION arcurrGain(INTEGER, INTEGER, NUMERIC, DATE)
 RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pAropenId ALIAS FOR $1;
index 2354753..4ebbbe1 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION asofinvbal(INTEGER, DATE) RETURNS SETOF invbal STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteId ALIAS FOR $1;
index b95beec..c4368de 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION asofinvnn(INTEGER, DATE) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteId ALIAS FOR $1;
index 824d72c..0e40841 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION asofinvqty(INTEGER, DATE) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteId ALIAS FOR $1;
diff --git a/foundation-database/public/functions/assessfinancecharge.sql b/foundation-database/public/functions/assessfinancecharge.sql
new file mode 100644 (file)
index 0000000..e75b6b6
--- /dev/null
@@ -0,0 +1,192 @@
+CREATE OR REPLACE FUNCTION assessFinanceCharge(pAropenid INTEGER,
+                                               pAssessDate DATE,
+                                               pAssessAmount NUMERIC) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
+-- See www.xtuple.com/CPAL for the full text of the software license.
+DECLARE
+  _fc           RECORD;
+  _ar           RECORD;
+  _invcheadid   INTEGER;
+
+BEGIN
+
+  -- cache some information
+  SELECT * INTO _fc FROM fincharg;
+  IF (NOT FOUND) THEN
+    RAISE EXCEPTION 'assessFinanceCharge, configuration not set.';
+  END IF;
+
+  SELECT * INTO _ar FROM aropen WHERE (aropen_id=pAropenid);
+  IF (NOT FOUND) THEN
+    RAISE EXCEPTION 'assessFinanceCharge, aropen not found.';
+  END IF;
+
+  -- create invoice head
+  INSERT INTO invchead
+    ( invchead_cust_id,
+      invchead_shipto_id,
+      invchead_ordernumber,
+      invchead_orderdate,
+      invchead_posted,
+      invchead_printed,
+      invchead_invcnumber,
+      invchead_invcdate,
+      invchead_shipdate,
+      invchead_ponumber,
+      invchead_shipvia,
+      invchead_fob,
+      invchead_billto_name,
+      invchead_billto_address1,
+      invchead_billto_address2,
+      invchead_billto_address3,
+      invchead_billto_city,
+      invchead_billto_state,
+      invchead_billto_zipcode,
+      invchead_billto_phone,
+      invchead_shipto_name,
+      invchead_shipto_address1,
+      invchead_shipto_address2,
+      invchead_shipto_address3,
+      invchead_shipto_city,
+      invchead_shipto_state,
+      invchead_shipto_zipcode,
+      invchead_shipto_phone,
+      invchead_salesrep_id,
+      invchead_commission,
+      invchead_terms_id,
+      invchead_freight,
+      invchead_misc_amount,
+      invchead_misc_descrip,
+      invchead_misc_accnt_id,
+      invchead_payment,
+      invchead_paymentref,
+      invchead_notes,
+      invchead_billto_country,
+      invchead_shipto_country,
+      invchead_prj_id,
+      invchead_curr_id,
+      invchead_gldistdate,
+      invchead_recurring,
+      invchead_recurring_interval,
+      invchead_recurring_type,
+      invchead_recurring_until,
+      invchead_recurring_invchead_id,
+      invchead_shipchrg_id,
+      invchead_taxzone_id,
+      invchead_void,
+      invchead_saletype_id,
+      invchead_shipzone_id )
+  SELECT
+      invchead_cust_id,
+      invchead_shipto_id,
+      invchead_ordernumber,
+      invchead_orderdate,
+      FALSE,
+      FALSE,
+      fetchInvcNumber(),
+      pAssessDate,
+      invchead_shipdate,
+      invchead_ponumber,
+      invchead_shipvia,
+      invchead_fob,
+      invchead_billto_name,
+      invchead_billto_address1,
+      invchead_billto_address2,
+      invchead_billto_address3,
+      invchead_billto_city,
+      invchead_billto_state,
+      invchead_billto_zipcode,
+      invchead_billto_phone,
+      invchead_shipto_name,
+      invchead_shipto_address1,
+      invchead_shipto_address2,
+      invchead_shipto_address3,
+      invchead_shipto_city,
+      invchead_shipto_state,
+      invchead_shipto_zipcode,
+      invchead_shipto_phone,
+      invchead_salesrep_id,
+      0.0,
+      invchead_terms_id,
+      0.0,
+      0.0,
+      NULL,
+      NULL,
+      0.0,
+      NULL,
+      '',
+      invchead_billto_country,
+      invchead_shipto_country,
+      invchead_prj_id,
+      invchead_curr_id,
+      NULL,
+      FALSE,
+      NULL,
+      NULL,
+      NULL,
+      NULL,
+      invchead_shipchrg_id,
+      invchead_taxzone_id,
+      invchead_void,
+      invchead_saletype_id,
+      invchead_shipzone_id
+  FROM invchead
+  WHERE (invchead_invcnumber=_ar.aropen_docnumber)
+  RETURNING invchead_id INTO _invcheadid;
+
+  -- create invoice item
+  INSERT INTO invcitem
+    ( invcitem_invchead_id,
+      invcitem_linenumber,
+      invcitem_item_id,
+      invcitem_warehous_id,
+      invcitem_custpn,
+      invcitem_number,
+      invcitem_descrip,
+      invcitem_ordered,
+      invcitem_billed,
+      invcitem_custprice,
+      invcitem_price,
+      invcitem_notes,
+      invcitem_salescat_id,
+      invcitem_taxtype_id,
+      invcitem_qty_uom_id,
+      invcitem_qty_invuomratio,
+      invcitem_price_uom_id,
+      invcitem_price_invuomratio,
+      invcitem_coitem_id,
+      invcitem_updateinv,
+      invcitem_rev_accnt_id )
+  VALUES
+    ( _invcheadid,
+      1,
+      -1,
+      -1,
+      NULL,
+      _fc.fincharg_markoninvoice,
+      'Finance Charge Assessment',
+      1.0,
+      1.0,
+      pAssessAmount,
+      pAssessAmount,
+      '',
+      _fc.fincharg_salescat_id,
+      NULL,
+      NULL,
+      1.0,
+      NULL,
+      1.0,
+      NULL,
+      FALSE,
+      _fc.fincharg_accnt_id );
+
+  -- update aropen
+  UPDATE aropen SET aropen_fincharg_date = pAssessDate,
+                    aropen_fincharg_amount = COALESCE(aropen_fincharg_amount, 0.0) + pAssessAmount
+  WHERE (aropen_id=pAropenid);
+
+
+  RETURN 0;
+
+END;
+$$ LANGUAGE 'plpgsql';
index 8efdfaa..bfd9b63 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION attachContact(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pcntctId    ALIAS FOR $1;
index 7bf8f4a..483873e 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION attachQuoteToOpportunity(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pQuheadid    ALIAS FOR $1;
index 3c90492..7ef9de3 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION attachSalesOrderToOpportunity(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSoheadid    ALIAS FOR $1;
index 260e11e..646a74b 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION averageSalesPrice(INTEGER, DATE, DATE) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index ffd98a0..05f1729 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION avgCost(pItemsiteid INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _value NUMERIC;
index 17a62cf..8538760 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION balanceItemsite(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index 0fc1c32..067cab8 100644 (file)
@@ -1,6 +1,6 @@
 CREATE OR REPLACE FUNCTION baseCurrID ()
     RETURNS INTEGER IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   returnVal INTEGER;
index 570861f..567b354 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION BOMContains(INTEGER, INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pparentitemid        ALIAS FOR $1;
index 4b88e13..8eccaf1 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION bomhistSequence(INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pHistid ALIAS FOR $1;
index 57451ee..65609fa 100644 (file)
@@ -1,11 +1,11 @@
 CREATE OR REPLACE FUNCTION bomitem(INTEGER) RETURNS SETOF bomitem AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT * FROM bomitem WHERE ((bomitem_parent_item_id=$1) AND (bomitem_rev_id=getActiveRevId('BOM',$1)));
 $$ LANGUAGE 'sql';
 
 CREATE OR REPLACE FUNCTION bomitem(INTEGER,INTEGER) RETURNS SETOF bomitem AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT * FROM bomitem WHERE ((bomitem_parent_item_id=$1) AND (bomitem_rev_id=$2));
 $$ LANGUAGE 'sql';
index b32f721..7beb066 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION bomLevelByItem(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
@@ -31,7 +31,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION bomLevelByItem(INTEGER,INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index 6be655f..7385fd7 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION bomworkEffective( INTEGER, DATE ) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
     workid ALIAS FOR $1;
index 1c406ab..9616ad4 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION bomworkExpired( INTEGER, DATE ) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
     workid ALIAS FOR $1;
index 1342098..1886cf0 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION bomworkItemSequence(INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWorkid ALIAS FOR $1;
index 24f27c5..5c28b51 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION bomworkSequence(INTEGER) RETURNS TEXT AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWorkid ALIAS FOR $1;
index 655e7f1..d377d9d 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION buildInvBal(integer) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteId ALIAS FOR $1;
index 76f6a35..04968bd 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION calcCobillAmt(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCobillid ALIAS FOR $1;
@@ -18,7 +18,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION calcCobillTax(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCobillid ALIAS FOR $1;
@@ -41,7 +41,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION calcCobmiscAmt(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCobmiscid ALIAS FOR $1;
@@ -59,7 +59,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION calcCobmiscTax(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCobmiscid ALIAS FOR $1;
index 1b2bcf1..00a2c26 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION calccashbudget(integer, integer, character) RETURNS numeric AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pAccntId ALIAS FOR $1;
index c8b643d..75b9929 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION calcCmheadAmt(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCmheadid ALIAS FOR $1;
@@ -17,7 +17,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION calcCmheadTax(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCmheadid ALIAS FOR $1;
diff --git a/foundation-database/public/functions/calcinvoiceamt.sql b/foundation-database/public/functions/calcinvoiceamt.sql
new file mode 100644 (file)
index 0000000..55d07b5
--- /dev/null
@@ -0,0 +1,61 @@
+CREATE OR REPLACE FUNCTION calcInvoiceAmt(pInvcheadid INTEGER) RETURNS NUMERIC STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
+-- See www.xtuple.com/CPAL for the full text of the software license.
+BEGIN
+
+  RETURN calcInvoiceAmt(pInvcheadid, 'T');
+
+END;
+$$ LANGUAGE 'plpgsql';
+
+CREATE OR REPLACE FUNCTION calcInvoiceAmt(pInvcheadid INTEGER,
+                                          pType TEXT) RETURNS NUMERIC STABLE AS $$
+-- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- See www.xtuple.com/CPAL for the full text of the software license.
+DECLARE
+  _subtotal NUMERIC := 0.0;
+  _cost NUMERIC := 0.0;
+  _tax NUMERIC := 0.0;
+  _freight NUMERIC := 0.0;
+  _misc NUMERIC := 0.0;
+  _amount NUMERIC := 0.0;
+
+BEGIN
+
+  -- pType: S = line item subtotal
+  --        T = total
+  --        X = tax
+  --        M = margin
+
+  SELECT COALESCE(SUM(ROUND((invcitem_billed * invcitem_qty_invuomratio) *
+                            (invcitem_price / COALESCE(invcitem_price_invuomratio, 1.0)), 2)), 0.0),
+         COALESCE(SUM(ROUND((invcitem_billed * invcitem_qty_invuomratio) *
+                            COALESCE(coitem_unitcost, itemCost(itemsite_id), 0.0), 2)), 0.0)
+         INTO _subtotal, _cost
+  FROM invcitem LEFT OUTER JOIN coitem ON (coitem_id=invcitem_coitem_id)
+                LEFT OUTER JOIN itemsite ON (itemsite_item_id=invcitem_item_id AND itemsite_warehous_id=invcitem_warehous_id)
+  WHERE (invcitem_invchead_id=pInvcheadid);
+
+  IF (pType IN ('T', 'X')) THEN
+    SELECT COALESCE(ROUND(SUM(taxdetail_tax), 2), 0.0) INTO _tax
+    FROM calculateTaxDetailSummary('I', pInvcheadid, 'T');
+  END IF;
+
+  IF (pType = 'T') THEN
+    SELECT COALESCE(invchead_freight, 0), COALESCE(invchead_misc_amount, 0)
+           INTO _freight, _misc
+    FROM invchead
+    WHERE (invchead_id=pinvcheadid);
+  END IF;
+
+  _amount := CASE pType WHEN 'S' THEN (_subtotal)
+                        WHEN 'T' THEN (_subtotal + _tax + _freight + _misc)
+                        WHEN 'X' THEN (_tax)
+                        WHEN 'M' THEN (_subtotal - _cost)
+                        ELSE 0.0
+             END;
+
+  RETURN _amount;
+
+END;
+$$ LANGUAGE 'plpgsql';
index 79c88e4..01672e3 100644 (file)
@@ -1,5 +1,5 @@
-CREATE OR REPLACE FUNCTION calcpendingarapplications(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION calcpendingarapplications(INTEGER) RETURNS NUMERIC STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   paropenid     ALIAS FOR $1;
diff --git a/foundation-database/public/functions/calcpurchaseorderamt.sql b/foundation-database/public/functions/calcpurchaseorderamt.sql
new file mode 100644 (file)
index 0000000..1f45ed3
--- /dev/null
@@ -0,0 +1,57 @@
+CREATE OR REPLACE FUNCTION calcPurchaseOrderAmt(pPoheadid INTEGER) RETURNS NUMERIC AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
+-- See www.xtuple.com/CPAL for the full text of the software license.
+BEGIN
+
+  RETURN calcPurchaseOrderAmt(pPoheadid, 'T');
+
+END;
+$$ LANGUAGE 'plpgsql';
+
+CREATE OR REPLACE FUNCTION calcPurchaseOrderAmt(pPoheadid INTEGER,
+                                                pType TEXT) RETURNS NUMERIC AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
+-- See www.xtuple.com/CPAL for the full text of the software license.
+DECLARE
+  _subtotal NUMERIC := 0;
+  _freightsub NUMERIC := 0;
+  _tax NUMERIC := 0;
+  _freight NUMERIC := 0;
+  _currid INTEGER := 0;
+  _effdate DATE := CURRENT_DATE;
+  _amount NUMERIC := 0;
+
+BEGIN
+
+  -- pType: S = line item subtotal
+  --        T = total
+  --        X = tax
+
+  SELECT COALESCE(SUM(ROUND(poitem_qty_ordered * poitem_unitprice, 2)), 0),
+         COALESCE(SUM(ROUND(poitem_freight, 2)), 0)
+         INTO _subtotal, _freightsub
+  FROM poitem
+  WHERE (poitem_pohead_id=pPoheadid);
+
+  SELECT COALESCE(SUM(tax), 0) INTO _tax
+  FROM ( SELECT COALESCE(ROUND(SUM(taxdetail_tax), 2), 0.0) AS tax
+         FROM tax JOIN calculateTaxDetailSummary('PO', pPoheadid, 'T') ON (taxdetail_tax_id=tax_id)
+         GROUP BY tax_id ) AS data;
+
+  SELECT COALESCE(pohead_freight, 0), pohead_curr_id, pohead_orderdate
+         INTO _freight, _currid, _effdate
+  FROM pohead
+  WHERE (pohead_id=pPoheadid);
+
+  _amount := currToBase(_currid,
+                        CASE pType WHEN 'S' THEN (_subtotal)
+                                   WHEN 'T' THEN (_subtotal + _tax + _freight + _freightsub)
+                                   WHEN 'X' THEN (_tax)
+                                   ELSE 0.0
+                        END,
+                        _effdate);
+
+  RETURN _amount;
+
+END;
+$$ LANGUAGE 'plpgsql';
diff --git a/foundation-database/public/functions/calcpurchaseorderduedate.sql b/foundation-database/public/functions/calcpurchaseorderduedate.sql
new file mode 100644 (file)
index 0000000..03d2413
--- /dev/null
@@ -0,0 +1,15 @@
+CREATE OR REPLACE FUNCTION calcPurchaseOrderDueDate(pPoheadid INTEGER) RETURNS DATE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
+-- See www.xtuple.com/CPAL for the full text of the software license.
+DECLARE
+  _result DATE;
+BEGIN
+
+  SELECT MIN(poitem_duedate) INTO _result
+  FROM poitem
+  WHERE (poitem_pohead_id=pPoheadid);
+
+  RETURN _result;
+
+END;
+$$ LANGUAGE 'plpgsql';
index bf14c70..4bb78e2 100644 (file)
@@ -1,32 +1,57 @@
-DROP FUNCTION IF EXISTS calcquoteamt(integer);
-CREATE OR REPLACE FUNCTION calcQuoteAmt(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION calcQuoteAmt(pQuheadid INTEGER) RETURNS NUMERIC STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
+-- See www.xtuple.com/CPAL for the full text of the software license.
+BEGIN
+
+  RETURN calcQuoteAmt(pQuheadid, 'T');
+
+END;
+$$ LANGUAGE 'plpgsql';
+
+CREATE OR REPLACE FUNCTION calcQuoteAmt(pQuheadid INTEGER,
+                                        pType TEXT) RETURNS NUMERIC STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
-  pQuheadid ALIAS FOR $1;
-  _subtotal NUMERIC := 0;
-  _tax NUMERIC := 0;
-  _freight NUMERIC := 0;
-  _misc NUMERIC := 0;
-  _amount NUMERIC := 0;
+  _subtotal NUMERIC := 0.0;
+  _cost NUMERIC := 0.0;
+  _tax NUMERIC := 0.0;
+  _freight NUMERIC := 0.0;
+  _misc NUMERIC := 0.0;
+  _amount NUMERIC := 0.0;
 
 BEGIN
 
+  -- pType: S = line item subtotal
+  --        T = total
+  --        X = tax
+  --        M = margin
+
   SELECT COALESCE(SUM(ROUND((quitem_qtyord * quitem_qty_invuomratio) *
-                            (quitem_price / quitem_price_invuomratio), 2)), 0) INTO _subtotal
+                            (quitem_price / quitem_price_invuomratio), 2)), 0.0),
+         COALESCE(SUM(ROUND((quitem_qtyord * quitem_qty_invuomratio) *
+                            quitem_unitcost, 2)), 0.0)
+         INTO _subtotal, _cost
   FROM quitem
   WHERE (quitem_quhead_id=pQuheadid);
 
-  SELECT COALESCE(SUM(tax), 0) INTO _tax
-  FROM ( SELECT ROUND(SUM(taxdetail_tax), 2) AS tax
-         FROM tax JOIN calculateTaxDetailSummary('Q', pQuheadid, 'T') ON (taxdetail_tax_id=tax_id)
-         GROUP BY tax_id ) AS data;
+  IF (pType IN ('T', 'X')) THEN
+    SELECT COALESCE(ROUND(SUM(taxdetail_tax), 2), 0.0) INTO _tax
+    FROM calculateTaxDetailSummary('Q', pQuheadid, 'T');
+  END IF;
 
-  SELECT COALESCE(quhead_freight, 0), COALESCE(quhead_misc, 0) INTO _freight, _misc
-  FROM quhead
-  WHERE (quhead_id=pQuheadid);
+  IF (pType = 'T') THEN
+    SELECT COALESCE(quhead_freight, 0), COALESCE(quhead_misc, 0) INTO _freight, _misc
+    FROM quhead
+    WHERE (quhead_id=pQuheadid);
+  END IF;
 
-  _amount := _subtotal + _tax + _freight + _misc;
+  _amount := CASE pType WHEN 'S' THEN (_subtotal)
+                        WHEN 'T' THEN (_subtotal + _tax + _freight + _misc)
+                        WHEN 'X' THEN (_tax)
+                        WHEN 'M' THEN (_subtotal - _cost)
+                        ELSE 0.0
+             END;
 
   RETURN _amount;
 
index fb3029e..886c44c 100644 (file)
@@ -1,33 +1,68 @@
-DROP FUNCTION IF EXISTS calcsalesorderamt(integer);
-CREATE OR REPLACE FUNCTION calcSalesOrderAmt(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION calcSalesOrderAmt(pCoheadid INTEGER) RETURNS NUMERIC STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
+-- See www.xtuple.com/CPAL for the full text of the software license.
+BEGIN
+
+  RETURN calcSalesOrderAmt(pCoheadid, 'T');
+
+END;
+$$ LANGUAGE 'plpgsql';
+
+CREATE OR REPLACE FUNCTION calcSalesOrderAmt(pCoheadid INTEGER,
+                                             pType TEXT) RETURNS NUMERIC STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
-  pCoheadid ALIAS FOR $1;
-  _subtotal NUMERIC := 0;
-  _tax NUMERIC := 0;
-  _freight NUMERIC := 0;
-  _misc NUMERIC := 0;
-  _amount NUMERIC := 0;
+  _subtotal NUMERIC := 0.0;
+  _cost NUMERIC := 0.0;
+  _tax NUMERIC := 0.0;
+  _freight NUMERIC := 0.0;
+  _misc NUMERIC := 0.0;
+  _credit NUMERIC := 0.0;
+  _amount NUMERIC := 0.0;
 
 BEGIN
 
+  -- pType: S = line item subtotal
+  --        T = total
+  --        B = balance due
+  --        C = allocated credits
+  --        X = tax
+  --        M = margin
+
   SELECT COALESCE(SUM(ROUND((coitem_qtyord * coitem_qty_invuomratio) *
-                            (coitem_price / coitem_price_invuomratio), 2)), 0) INTO _subtotal
+                            (coitem_price / coitem_price_invuomratio), 2)), 0.0),
+         COALESCE(SUM(ROUND((coitem_qtyord * coitem_qty_invuomratio) *
+                            coitem_unitcost, 2)), 0.0)
+         INTO _subtotal, _cost
   FROM coitem
   WHERE (coitem_cohead_id=pCoheadid)
     AND (coitem_status != 'X');
 
-  SELECT COALESCE(SUM(tax), 0) INTO _tax
-  FROM ( SELECT ROUND(SUM(taxdetail_tax), 2) AS tax
-         FROM tax JOIN calculateTaxDetailSummary('S', pCoheadid, 'T') ON (taxdetail_tax_id=tax_id)
-         GROUP BY tax_id ) AS data;
+  IF (pType IN ('T', 'B', 'X')) THEN
+    SELECT COALESCE(ROUND(SUM(taxdetail_tax), 2), 0.0) INTO _tax
+    FROM calculateTaxDetailSummary('S', pCoheadid, 'T');
+  END IF;
 
-  SELECT COALESCE(cohead_freight, 0), COALESCE(cohead_misc, 0) INTO _freight, _misc
-  FROM cohead
-  WHERE (cohead_id=pCoheadid);
+  IF (pType IN ('T', 'B', 'C')) THEN
+    SELECT COALESCE(cohead_freight, 0), COALESCE(cohead_misc, 0),
+           COALESCE(SUM(currToCurr(aropenalloc_curr_id, cohead_curr_id,
+                                   aropenalloc_amount, CURRENT_DATE)),0)
+           INTO _freight, _misc, _credit
+    FROM cohead
+         LEFT OUTER JOIN aropenalloc ON (aropenalloc_doctype='S' AND aropenalloc_doc_id=cohead_id)
+    WHERE (cohead_id=pCoheadid)
+    GROUP BY cohead_freight, cohead_misc, cohead_curr_id;
+  END IF;
 
-  _amount := _subtotal + _tax + _freight + _misc;
+  _amount := CASE pType WHEN 'S' THEN (_subtotal)
+                        WHEN 'T' THEN (_subtotal + _tax + _freight + _misc)
+                        WHEN 'B' THEN (_subtotal + _tax + _freight + _misc - _credit)
+                        WHEN 'C' THEN (_credit)
+                        WHEN 'X' THEN (_tax)
+                        WHEN 'M' THEN (_subtotal - _cost)
+                        ELSE 0.0
+             END;
 
   RETURN _amount;
 
index 42e1f68..3eaeb9d 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION calcShipFreight(integer) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pShipheadId ALIAS FOR $1;
index c248643..3a50044 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION calcTotalSlipQty(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTagid ALIAS FOR $1;
index e58697b..4748c94 100644 (file)
@@ -1,7 +1,7 @@
 
 CREATE OR REPLACE FUNCTION calculateFreightDetail(integer,integer,text,integer,integer,text,date,text,integer,character varying,integer,integer,numeric)
   RETURNS SETOF freightData AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCustId ALIAS FOR $1;
index 9dc9681..195b9cc 100644 (file)
@@ -2,7 +2,7 @@
 CREATE OR REPLACE FUNCTION calculatesubtax(integer, date, integer, numeric, integer)
   RETURNS SETOF taxdetail AS
 $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTaxCodeId ALIAS FOR $1;
index 46fc1c4..0849591 100644 (file)
@@ -1,7 +1,7 @@
 CREATE OR REPLACE FUNCTION calculatetax(integer, integer, date, integer, numeric)
   RETURNS numeric AS
 $BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTaxZoneId ALIAS FOR  $1;
index 85172c9..3d7d36b 100644 (file)
@@ -2,7 +2,7 @@
 CREATE OR REPLACE FUNCTION calculatetaxdetail(integer, integer, date, integer, numeric)
   RETURNS SETOF taxdetail AS
 $BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTaxZoneId ALIAS FOR  $1;
index 334b644..df47bb4 100644 (file)
@@ -2,7 +2,7 @@
 CREATE OR REPLACE FUNCTION calculatetaxdetailline(text, integer) 
   RETURNS SETOF taxdetail AS
 $BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pOrderType ALIAS FOR $1;
index 610f016..b4ffa55 100644 (file)
@@ -2,7 +2,7 @@
 CREATE OR REPLACE FUNCTION calculatetaxdetailsummary(text, integer, text)
   RETURNS SETOF taxdetail AS
 $BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pOrderType ALIAS FOR $1;
index cb91913..1b6a8fe 100644 (file)
@@ -1,7 +1,7 @@
 CREATE OR REPLACE FUNCTION calculatetaxhist(text, integer, integer, integer, date, integer, numeric)
   RETURNS boolean AS
 $BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTableName ALIAS FOR $1;
index 5a2e719..66e5f70 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION calcVoucherFreight(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVoucherid ALIAS FOR $1;
@@ -17,7 +17,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION calcVoucherTax(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVoucherid ALIAS FOR $1;
@@ -39,7 +39,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION calcVoucherAmt(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVoucherid ALIAS FOR $1;
index 71f743b..1630dc9 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION calcWooperStartStub(INTEGER, INTEGER) RETURNS DATE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoId         ALIAS FOR $1;
index f00e21e..a5a4674 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION cancelBillingSelection(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCobmiscid ALIAS FOR $1;
index 2590e21..8e22c3e 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION changeAccountingPeriodDates(INTEGER, DATE, DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPeriodid ALIAS FOR $1;
index 123317b..0845cbd 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION changeAccountingYearPeriodDates(INTEGER, DATE, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPeriodid ALIAS FOR $1;
index e68c9ea..53db3a8 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION changeFKeyPointers(TEXT, TEXT, INTEGER, INTEGER, TEXT[], BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSchema       ALIAS FOR $1;
index 76965a9..6887029 100644 (file)
@@ -1,14 +1,22 @@
-DROP FUNCTION IF EXISTS changepoitemduedate(integer, date);
-CREATE OR REPLACE FUNCTION changePoitemDueDate(INTEGER, DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION changePoitemDueDate(pPoitemid INTEGER,
+                                               pDate DATE) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
-DECLARE
-  pPoitemid ALIAS FOR $1;
-  pDate ALIAS FOR $2;
+BEGIN
+
+  RETURN changePoitemDueDate(pPoitemid, pDate, false);
+
+END;
+$$ LANGUAGE 'plpgsql';
 
+CREATE OR REPLACE FUNCTION changePoitemDueDate(pPoitemid INTEGER,
+                                               pDate DATE,
+                                               pBySO BOOLEAN) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
+-- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
 
-  IF ( ( SELECT (poitem_status IN (''C''))
+  IF ( ( SELECT (poitem_status IN ('C'))
          FROM poitem
          WHERE (poitem_id=pPoitemid) ) ) THEN
     RETURN -1;
@@ -18,7 +26,20 @@ BEGIN
   SET poitem_duedate=pDate
   WHERE (poitem_id=pPoitemid);
 
+  IF (pBySO) THEN
+    --Generate the PoItemUpdatedBySo event
+    PERFORM postEvent('PoItemUpdatedBySo', 'P', poitem_id,
+                      itemsite_warehous_id,
+                      (pohead_number || '-'|| poitem_linenumber || ': ' || item_number),
+                      NULL, NULL, NULL, NULL)
+    FROM poitem JOIN pohead ON (pohead_id=poitem_pohead_id)
+                JOIN itemsite ON (itemsite_id=poitem_itemsite_id)
+                JOIN item ON (item_id=itemsite_item_id)
+    WHERE (poitem_id=pPoitemid)
+      AND (poitem_duedate <= (CURRENT_DATE + itemsite_eventfence));
+  END IF;
+
   RETURN pPoitemid;
 
 END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
index 558af5e..09958b3 100644 (file)
@@ -1,14 +1,24 @@
-DROP FUNCTION IF EXISTS changepoitemqty(integer, numeric);
-CREATE OR REPLACE FUNCTION changePoitemQty(INTEGER, NUMERIC) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION changePoitemQty(pPoitemid INTEGER,
+                                           pQty NUMERIC) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
+-- See www.xtuple.com/CPAL for the full text of the software license.
+BEGIN
+
+  RETURN changePoitemQty(pPoitemid, pQty, false);
+
+END;
+$$ LANGUAGE 'plpgsql';
+
+CREATE OR REPLACE FUNCTION changePoitemQty(pPoitemid INTEGER,
+                                           pQty NUMERIC,
+                                           pBySO BOOLEAN) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
-  pPoitemid ALIAS FOR $1;
-  pQty ALIAS FOR $2;
 
 BEGIN
 
-  IF ( ( SELECT (poitem_status IN (''C''))
+  IF ( ( SELECT (poitem_status IN ('C'))
          FROM poitem
          WHERE (poitem_id=pPoitemid) ) ) THEN
     RETURN -1;
@@ -18,7 +28,20 @@ BEGIN
   SET poitem_qty_ordered=pQty
   WHERE (poitem_id=pPoitemid);
 
+  IF (pBySO) THEN
+    --Generate the PoItemUpdatedBySo event
+    PERFORM postEvent('PoItemUpdatedBySo', 'P', poitem_id,
+                      itemsite_warehous_id,
+                      (pohead_number || '-'|| poitem_linenumber || ': ' || item_number),
+                      NULL, NULL, NULL, NULL)
+    FROM poitem JOIN pohead ON (pohead_id=poitem_pohead_id)
+                JOIN itemsite ON (itemsite_id=poitem_itemsite_id)
+                JOIN item ON (item_id=itemsite_item_id)
+    WHERE (poitem_id=pPoitemid)
+      AND (poitem_duedate <= (CURRENT_DATE + itemsite_eventfence));
+  END IF;
+
   RETURN pPoitemid;
 
 END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
index b9f92d2..441be59 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION changePrDate(INTEGER, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPrid ALIAS FOR $1;
index 714dbd6..9c316e5 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION changePrQty(INTEGER, NUMERIC) RETURNS BOOL AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPrid ALIAS FOR $1;
index 8090b74..fb4773c 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION changePseudoFKeyPointers(TEXT, TEXT, TEXT, INTEGER, TEXT, TEXT, INTEGER, TEXT, TEXT, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSchema       ALIAS FOR $1;
diff --git a/foundation-database/public/functions/changepurchasedropship.sql b/foundation-database/public/functions/changepurchasedropship.sql
new file mode 100644 (file)
index 0000000..e290798
--- /dev/null
@@ -0,0 +1,52 @@
+CREATE OR REPLACE FUNCTION changePurchaseDropShip(pCoitemId INTEGER,
+                                                  pPoitemId INTEGER,
+                                                  pDropShip BOOLEAN) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
+-- See www.xtuple.com/CPAL for the full text of the software license.
+DECLARE
+  _s RECORD;
+  _w RECORD;
+  _p RECORD;
+  _result INTEGER;
+  _poitemid INTEGER;
+
+BEGIN
+
+  -- Check for existing poitem for this coitem
+  SELECT * INTO _p
+  FROM poitem JOIN pohead ON (pohead_id=poitem_pohead_id)
+  WHERE (poitem_id=pPoitemId)
+    AND (poitem_order_id=pCoitemId)
+    AND (poitem_order_type='S');
+  IF (NOT FOUND) THEN
+    RAISE EXCEPTION 'Change Purchase Drop Ship PO not found';
+  END IF;
+
+  SELECT * INTO _s
+  FROM coitem JOIN cohead ON (cohead_id = coitem_cohead_id)
+    LEFT OUTER JOIN shiptoinfo ON (cohead_shipto_id = shipto_id)
+    LEFT OUTER JOIN cntct ON (shipto_cntct_id = cntct_id)
+    LEFT OUTER JOIN addr ON (shipto_addr_id = addr_id)
+  WHERE (coitem_id = pCoitemId);
+  IF (NOT FOUND) THEN
+    RETURN -1;
+  END IF;
+
+  IF (_p.pohead_status != 'U') THEN
+    RETURN -3;
+  END IF;
+
+  SELECT deletePoitem(_p.poitem_id) INTO _result;
+  IF (_result < 0) THEN
+    RETURN _result;
+  END IF;
+
+  SELECT createPurchaseToSale(_s.coitem_id, _p.poitem_itemsrc_id,
+                              pDropShip, _s.coitem_qtyord,
+                              _s.coitem_scheddate, _p.poitem_unitprice)
+     INTO _poitemid;
+  
+  RETURN _poitemid;
+
+END;
+$$ LANGUAGE 'plpgsql' VOLATILE;
index c17c953..7088f5e 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION changeWoDates(INTEGER, DATE, DATE, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE 
   pWoid ALIAS FOR $1;
@@ -23,19 +23,12 @@ BEGIN
     returnCode := 0;
 
   ELSIF (_p.wo_status IN ('R','I')) THEN
-    INSERT INTO evntlog (evntlog_evnttime, evntlog_username, evntlog_evnttype_id,
-                         evntlog_ordtype, evntlog_ord_id, evntlog_warehous_id, evntlog_number,
-                         evntlog_olddate, evntlog_newdate)
-    SELECT CURRENT_TIMESTAMP, evntnot_username, evnttype_id,
-           'W', wo_id, itemsite_warehous_id, formatWoNumber(wo_id),
-           wo_duedate, pDueDate
-    FROM evntnot, evnttype, itemsite, item, wo
-    WHERE ( (evntnot_evnttype_id=evnttype_id)
-     AND (evntnot_warehous_id=itemsite_warehous_id)
-     AND (wo_itemsite_id=itemsite_id)
-     AND (itemsite_item_id=item_id)
-     AND (evnttype_name='RWoDueDateRequestChange')
-     AND (wo_id=pWoid) );
+    PERFORM postEvent('RWoDueDateRequestChange', 'W', wo_id,
+                      itemsite_warehous_id, formatWoNumber(wo_id),
+                      NULL, NULL, pDueDate, wo_duedate)
+    FROM wo JOIN itemsite ON (itemsite_id=wo_itemsite_id)
+            JOIN item ON (item_id=itemsite_item_id)
+    WHERE (wo_id=pWoid);
 
      returnCode := 0;
 
index 6ac5e90..7677f21 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION changeWoProject(INTEGER, INTEGER, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoid ALIAS FOR $1;
index 376435f..f2865c8 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION changeWoQty(INTEGER, NUMERIC, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoid ALIAS FOR $1;
@@ -24,19 +24,12 @@ BEGIN
   END IF;
 
   IF (_r.wo_status IN ('R','I')) THEN
-    INSERT INTO evntlog (evntlog_evnttime, evntlog_username, evntlog_evnttype_id,
-                         evntlog_ordtype, evntlog_ord_id, evntlog_warehous_id, evntlog_number,
-                         evntlog_oldvalue, evntlog_newvalue)
-    SELECT CURRENT_TIMESTAMP, evntnot_username, evnttype_id,
-           'W', wo_id, itemsite_warehous_id, formatWoNumber(wo_id),
-           wo_qtyord, pQty
-    FROM evntnot, evnttype, itemsite, item, wo
-    WHERE ( (evntnot_evnttype_id=evnttype_id)
-     AND (evntnot_warehous_id=itemsite_warehous_id)
-     AND (wo_itemsite_id=itemsite_id)
-     AND (itemsite_item_id=item_id)
-     AND (evnttype_name='RWoQtyRequestChange')
-     AND (wo_id=pWoid) );
+    PERFORM postEvent('RWoQtyRequestChange', 'W', wo_id,
+                      itemsite_warehous_id, formatWoNumber(wo_id),
+                      pQty, wo_qtyord, NULL, NULL)
+    FROM wo JOIN itemsite ON (itemsite_id=wo_itemsite_id)
+            JOIN item ON (item_id=itemsite_item_id)
+    WHERE (wo_id=pWoid);
 
      _result = 0;
   END IF;
index d6852b5..1f5d7d4 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION characteristicsToString(TEXT, INTEGER, TEXT, TEXT) RETURNS TEXT AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTargetType ALIAS FOR $1;
index 9450404..70486dd 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION checkCreditMemoSitePrivs(INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCmheadid ALIAS FOR $1;
index 2eb8458..aebb02d 100644 (file)
@@ -1,6 +1,6 @@
 CREATE OR REPLACE FUNCTION checkDetailFormatted(INTEGER, INTEGER) RETURNS SETOF checkdata
 AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCheckheadid ALIAS FOR $1;
@@ -116,12 +116,31 @@ BEGIN
     formatMoney(checkitem_discount) AS disc_cred
   FROM checkitem, apopen
   WHERE ((checkitem_checkhead_id=pCheckheadid)
-    AND  (checkitem_vouchernumber = apopen_docnumber)
+    AND  (checkitem_apopen_id = apopen_id)
     AND  (apopen_doctype = 'D'))
   
   UNION
   
-  SELECT --CREDITs--------------------------
+  SELECT --CREDIT MEMO -------------------------
+    2 AS ord,
+    1 AS sequence_value,
+    checkitem_invcnumber,
+    checkitem_ponumber,
+    formatMoney(checkitem_amount * -1.0) AS f_amount,
+    'Credit Memo PO#: ' || checkitem_ponumber AS doc_number,
+    ''  AS f_docdate,
+    'Credit Memo: ' || checkitem_vouchernumber AS doc_reference,
+    checkitem_vouchernumber AS vouchernumber,
+    '' AS amount,
+    formatMoney(checkitem_amount) AS disc_cred
+  FROM checkitem, apopen
+  WHERE ((checkitem_checkhead_id=pCheckheadid)
+    AND  (checkitem_apopen_id = apopen_id)
+    AND  (apopen_doctype = 'C'))
+  
+  UNION
+  
+  SELECT --CREDITs FOR VOUCHERS-----------------
     3 AS ord,
     1 AS sequence_value,
     checkitem_invcnumber,
@@ -131,13 +150,38 @@ BEGIN
     formatDate(vohead_docdate) AS f_docdate,
     'Credit Applied: ' || apapply_source_doctype || ' ' ||
                           apapply_source_docnumber AS doc_reference,
-    'Voucher ' || checkitem_vouchernumber AS vouchernumber,
+    'Voucher: ' || checkitem_vouchernumber AS vouchernumber,
     '' AS amount,
     formatMoney((apapply_amount)) AS disc_cred
   FROM checkitem, vohead, apapply
   WHERE ((checkitem_checkhead_id=pCheckheadid)
     AND  (checkitem_vouchernumber = vohead_number)
-    AND  (apapply_target_docnumber = checkitem_vouchernumber ))
+    AND  (apapply_target_docnumber = checkitem_vouchernumber)
+    AND  (apapply_target_doctype = 'V')
+    AND  (apapply_source_doctype = 'C'))
+  
+  UNION 
+  
+  SELECT --CREDITs FOR DEBIT MEMOS-----------
+    3 AS ord,
+    1 AS sequence_value,
+    checkitem_invcnumber,
+    checkitem_ponumber,
+    formatMoney(checkitem_amount) AS f_amount,
+    'Debit Memo PO#: ' || checkitem_ponumber AS doc_number,
+    '' AS f_docdate,
+    'Credit Applied: ' || apapply_source_doctype || ' ' ||
+                          apapply_source_docnumber AS doc_reference,
+    'Debit Memo: ' || checkitem_vouchernumber AS vouchernumber,
+    '' AS amount,
+    formatMoney((apapply_amount)) AS disc_cred
+  FROM checkitem, apopen, apapply
+  WHERE ((checkitem_checkhead_id=pCheckheadid)
+    AND  (checkitem_vouchernumber = apopen_docnumber)
+    AND  (apopen_doctype = 'D')
+    AND  (apapply_target_docnumber = checkitem_vouchernumber)
+    AND  (apapply_target_doctype = 'D')
+    AND  (apapply_source_doctype = 'C'))
   
   UNION 
   
index 47f1cac..b31153a 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION checkInvoiceSitePrivs(INTEGER) RETURNS BOOLEAN STABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pInvcheadid ALIAS FOR $1;
index e9a82be..ed117d7 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION checkPOSitePrivs(INTEGER) RETURNS BOOLEAN STABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPoheadid ALIAS FOR $1;
index 2a41620..91cbb3d 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION checkPrivilege(text) RETURNS BOOLEAN STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPrivilege ALIAS FOR $1;
index 9a4f687..1bc8226 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION checkQuoteSitePrivs(INTEGER) RETURNS BOOLEAN STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pQuheadid ALIAS FOR $1;
@@ -12,7 +12,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION checkQuoteSitePrivs(INTEGER, INTEGER) RETURNS BOOLEAN STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pQuheadid ALIAS FOR $1;
index 7e5a1d9..b8064d7 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION checkRASitePrivs(INTEGER) RETURNS BOOLEAN STABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pRaheadid ALIAS FOR $1;
index fbb3e45..b637d4d 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION checkShipmentSitePrivs(INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pShipheadid ALIAS FOR $1;
index 62d767b..61ff7f2 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION checkSOSitePrivs(INTEGER) RETURNS BOOLEAN STABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSoheadid ALIAS FOR $1;
index a844b23..dd16d39 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION checkVoucherSitePrivs(INTEGER) RETURNS BOOLEAN STABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVoheadid ALIAS FOR $1;
index cbd5878..e841fb2 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION clearNumberIssue(psequence TEXT, pnumber INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   __seqiss     seqiss[];
@@ -56,7 +56,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION clearNumberIssue(psequence TEXT, pnumber TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _castpnumber  INTEGER;
index 79c16a1..330ad32 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION clearPayment(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pApselectid ALIAS FOR $1;
index b2ac699..aa5fc3d 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION closeAccountingPeriod(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPeriodid ALIAS FOR $1;
index 54ddc8e..d7bf8fa 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION closeAccountingYearPeriod(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pYearPeriodid ALIAS FOR $1;
index 91f511c..29fe33d 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION closePo(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPoheadid ALIAS FOR $1;
index 1afed4f..f3c090e 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION closeWo(INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoid ALIAS FOR $1;
@@ -13,7 +13,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION closeWo(INTEGER, BOOLEAN, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoid ALIAS FOR $1;
@@ -25,15 +25,20 @@ DECLARE
 
 BEGIN
 
+  --Comment this out
+  --In addition to IssueToShipping driving PostProduction,
+  --not PostProduction can drive IssueToShipping.
+  --Must allow closing of Job items
+
   --If this is item type Job then we cannot close here
-  SELECT itemsite_costmethod INTO _check
-  FROM wo,itemsite
-  WHERE ((wo_id=pWoid)
-  AND (wo_itemsite_id=itemsite_id)
-  AND (itemsite_costmethod = 'J'));
-  IF (FOUND) THEN
-    RAISE EXCEPTION 'Work orders for Job items are closed when all quantities are shipped';
-  END IF;
+  --SELECT itemsite_costmethod INTO _check
+  --FROM wo,itemsite
+  --WHERE ((wo_id=pWoid)
+  --AND (wo_itemsite_id=itemsite_id)
+  --AND (itemsite_costmethod = 'J'));
+  --IF (FOUND) THEN
+  --  RAISE EXCEPTION 'Work orders for Job items are closed when all quantities are shipped';
+  --END IF;
 
   SELECT formatWoNumber(pWoid) INTO _woNumber;
 
index 38f80ab..eb96470 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION cntct() RETURNS SETOF cntct AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _row cntct%ROWTYPE;
index 23dcd49..0d47336 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION cntctdups(text, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean, boolean) RETURNS SETOF cntctdup AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSearchText ALIAS FOR $1;
index 03ee786..06464ed 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION cntctmerge(integer, integer, boolean) RETURNS boolean AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSourceCntctId ALIAS FOR $1;
index 460a020..f7bbec4 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION cntctrestore(integer) RETURNS boolean AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCntctId ALIAS FOR $1;
index 591a569..73f5b5a 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION cntctselect(integer, boolean) RETURNS boolean AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCntctId ALIAS FOR $1;
index 48f6ac0..85deca6 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION cntctselectcol(integer, integer) RETURNS boolean AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCntctId ALIAS FOR $1;
index b0cc98b..9d3367d 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION cntctused(integer) RETURNS boolean AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCntctId ALIAS FOR $1;
index cd7f7a5..f16fe08 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION coheadstatecolor(INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCoheadId    ALIAS FOR $1;
diff --git a/foundation-database/public/functions/compareversion.sql b/foundation-database/public/functions/compareversion.sql
new file mode 100644 (file)
index 0000000..3687f89
--- /dev/null
@@ -0,0 +1,67 @@
+CREATE OR REPLACE FUNCTION public.compareversion(text, text DEFAULT split_part(version(), ' '::text, 2))
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
+-- See www.xtuple.com/CPAL for the full text of the software license.
+-- Returns 1 if the left version is greater than the right version
+-- -1 if the right is greater than the left
+--  0 if the versions are equal.
+-- parameter two defaults to current server version
+  RETURNS integer AS
+$BODY$
+DECLARE
+  _leftVersion ALIAS FOR $1;
+  _rightVersion ALIAS FOR $2;
+  _leftMajor SMALLINT;
+  _leftMinor SMALLINT;
+  _leftPatch SMALLINT;
+  _rightMajor SMALLINT;
+  _rightMinor SMALLINT;
+  _rightPatch SMALLINT;
+  _returnCode SMALLINT;
+  DEBUG BOOLEAN := false;
+BEGIN
+
+-- left
+SELECT  substring(_leftVersion FROM $$(\d+)\.\d+\.\d+$$)::SMALLINT, 
+       substring(_leftVersion FROM $$\d+\.(\d+)\.\d+$$)::SMALLINT, 
+       substring(_leftVersion FROM $$\d+\.\d+\.(\d+)$$)::SMALLINT 
+       INTO _leftMajor, _leftMinor, _leftPatch;
+
+IF (DEBUG)
+  THEN RAISE NOTICE 'Left Version --> % Major --> % Minor --> % Patch --> % ', _leftVersion, _leftMajor, _leftMinor, _leftPatch;
+END IF;
+
+-- right
+SELECT  substring(_rightVersion FROM $$(\d+)\.\d+\.\d+$$)::SMALLINT, 
+       substring(_rightVersion FROM $$\d+\.(\d+)\.\d+$$)::SMALLINT, 
+       substring(_rightVersion FROM $$\d+\.\d+\.(\d+)$$)::SMALLINT 
+       INTO _rightMajor, _rightMinor, _rightPatch;
+
+IF (DEBUG)
+ THEN RAISE NOTICE 'Right Version --> % Major --> % Minor --> % Patch --> % ', _rightVersion, _rightMajor, _rightMinor, _rightPatch;
+END IF;
+
+-- check major version
+IF (_leftMajor > _rightMajor) THEN _returnCode := 1;
+ELSIF (_leftMajor < _rightMajor) THEN _returnCode := -1;
+ELSIF (_leftMajor = _rightMajor) THEN
+  -- if major is equal, check minor version
+  IF (_leftMinor > _rightMinor) THEN _returnCode := 1;
+  ELSIF (_leftMinor < _rightMinor) THEN _returnCode := -1;
+  ELSIF (_leftMinor = _rightMinor) THEN
+    -- if major and minor are equal, check patch version
+    IF (_leftPatch > _rightPatch) THEN _returnCode := 1;
+    ELSIF (_leftPatch < _rightPatch) THEN _returnCode := -1;
+    ELSIF (_leftPatch = _rightPatch) THEN _returnCode := 0;
+    END IF;
+  END IF;
+-- if we somehow don't match those three operators it probably means someone passed in a version that wasn't in numerical major.minor.patch format
+ELSE RAISE EXCEPTION 'One or more of the version parameters is invalid. Expected numerical Major.Minor.Patch version string. Left --> % Right --> %', _leftVersion, _rightVersion;
+END IF;
+
+RETURN _returnCode;
+
+END;
+$BODY$
+  LANGUAGE plpgsql STABLE;
+ALTER FUNCTION public.compareversion(text, text)
+  OWNER TO admin;
index 84cf6b4..d0a18a6 100644 (file)
@@ -1,7 +1,7 @@
 DROP AGGREGATE IF EXISTS concatagg(TEXT);
 
 CREATE OR REPLACE FUNCTION concataggSfunc(TEXT, TEXT) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   prevstate     ALIAS FOR $1;
index 4cda0fa..db2ee02 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION consolidateLocations(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index a0b7890..526e771 100644 (file)
@@ -5,7 +5,7 @@
                 WHERE crmacct_cust_id=pCustId;
  */
 CREATE OR REPLACE FUNCTION convertCustomerToProspect(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCustId     ALIAS FOR $1;
index 33a1931..90bf314 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION convertProspectToCustomer(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN convertProspectToCustomer($1, FALSE);
@@ -7,7 +7,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION convertProspectToCustomer(INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pProspectId ALIAS FOR $1;
index d764ef5..095a778 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION convertQuote(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pQuheadid ALIAS FOR $1;
@@ -31,15 +31,11 @@ BEGIN
    WHERE ((itemsite_id IS NULL)
      AND  (quitem_quhead_id=pQuheadid));
   IF (FOUND) THEN
-    INSERT INTO evntlog (evntlog_evnttime, evntlog_username, evntlog_evnttype_id,
-                         evntlog_ordtype, evntlog_ord_id, evntlog_warehous_id, evntlog_number)
-    SELECT CURRENT_TIMESTAMP, evntnot_username, evnttype_id,
-           'Q', quhead_id, quhead_warehous_id, quhead_number
-    FROM evntnot, evnttype, quhead
-    WHERE ( (evntnot_evnttype_id=evnttype_id)
-     AND (evntnot_warehous_id=quhead_warehous_id)
-     AND (evnttype_name='CannotConvertQuote')
-     AND (quhead_id=pQuheadid) );
+    PERFORM postEvent('CannotConvertQuote', 'Q', quhead_id,
+                      quhead_warehous_id, quhead_number,
+                      NULL, NULL, NULL, NULL)
+    FROM quhead
+    WHERE (quhead_id=pQuheadid);
 
     RETURN -1;
   END IF;
index 30193b2..5c68dc2 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION convertQuoteToInvoice(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pQuheadid ALIAS FOR $1;
@@ -31,15 +31,11 @@ BEGIN
    WHERE ((itemsite_id IS NULL)
      AND  (quitem_quhead_id=pQuheadid));
   IF (FOUND) THEN
-    INSERT INTO evntlog (evntlog_evnttime, evntlog_username, evntlog_evnttype_id,
-                         evntlog_ordtype, evntlog_ord_id, evntlog_warehous_id, evntlog_number)
-    SELECT CURRENT_TIMESTAMP, evntnot_username, evnttype_id,
-           'Q', quhead_id, quhead_warehous_id, quhead_number
-    FROM evntnot, evnttype, quhead
-    WHERE ( (evntnot_evnttype_id=evnttype_id)
-     AND (evntnot_warehous_id=quhead_warehous_id)
-     AND (evnttype_name='CannotConvertQuote')
-     AND (quhead_id=pQuheadid) );
+    PERFORM postEvent('CannotConvertQuote', 'Q', quhead_id,
+                      quhead_warehous_id, quhead_number,
+                      NULL, NULL, NULL, NULL)
+    FROM quhead
+    WHERE (quhead_id=pQuheadid);
 
     RETURN -1;
   END IF;
index 4c00775..d7bd612 100644 (file)
@@ -1,6 +1,6 @@
 CREATE OR REPLACE FUNCTION copyBOM(pSItemid       INTEGER,
                                    pTItemid       INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _result INTEGER;
@@ -17,11 +17,12 @@ $$ LANGUAGE 'plpgsql';
 CREATE OR REPLACE FUNCTION copyBOM(pSItemid       INTEGER,
                                    pTItemid       INTEGER,
                                    pCopyUsedAt    BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _bh RECORD;
   _bi RECORD;
+  _bomheadfound BOOLEAN := FALSE;
   _bomheadid INTEGER;
   _bomitemid INTEGER;
   _bomworksetid INTEGER;
@@ -37,15 +38,19 @@ BEGIN
   WHERE ((bomhead_item_id=pSItemid)
     AND  (bomhead_rev_id=getActiveRevID('BOM', pSItemid)));
 
-  IF (NOT FOUND) THEN
-    RETURN -1;
-  END IF;
+--  bomhead may not exist
+--  IF (NOT FOUND) THEN
+--    RETURN -1;
+--  END IF;
+    IF (FOUND) THEN
+      _bomheadfound := TRUE;
+    END IF;
 
 --  Make sure that source bomitems exist
   SELECT bomitem_id INTO _bomitemid
   FROM bomitem
-  WHERE ((bomitem_parent_item_id=_bh.bomhead_item_id)
-    AND  (bomitem_rev_id=_bh.bomhead_rev_id))
+  WHERE ((bomitem_parent_item_id=pSItemid)
+    AND  (bomitem_rev_id=getActiveRevID('BOM', pSItemid)))
   LIMIT 1;
 
   IF (NOT FOUND) THEN
@@ -87,12 +92,14 @@ BEGIN
     AND  (bomhead_rev_id= -1));
 
   IF (NOT FOUND) THEN
-    INSERT INTO bomhead
-    ( bomhead_item_id, bomhead_serial, bomhead_docnum,
-      bomhead_batchsize, bomhead_requiredqtyper )
-    VALUES
-    ( pTItemid, _bh.bomhead_serial, _bh.bomhead_docnum,
-      _bh.bomhead_batchsize, _bh.bomhead_requiredqtyper );
+    IF (_bomheadfound) THEN
+      INSERT INTO bomhead
+      ( bomhead_item_id, bomhead_serial, bomhead_docnum,
+        bomhead_batchsize, bomhead_requiredqtyper )
+      VALUES
+      ( pTItemid, _bh.bomhead_serial, _bh.bomhead_docnum,
+        _bh.bomhead_batchsize, _bh.bomhead_requiredqtyper );
+    END IF;
   END IF;
 
   FOR _bi IN SELECT bomitem.*
index 21988aa..6b64a74 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION copyBudget(INTEGER, TEXT, TEXT, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pBudgheadid ALIAS FOR $1;
index 67bf6c8..5fc7a0d 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION copycmd(INTEGER, TEXT, TEXT) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCmdId       ALIAS FOR $1;
index ffafc62..8cc9bf7 100644 (file)
@@ -2,7 +2,7 @@ CREATE OR REPLACE FUNCTION copyContract(pContrctid INTEGER,
                                         pNumber TEXT,
                                         pEffective DATE,
                                         pExpires DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _contrctid INTEGER;
index 197fb30..34f7ada 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION copyFinancialGroup(INTEGER, INTEGER, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSourceGroup ALIAS FOR $1;
index 0c7d757..2b7de3b 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION copyGLSeries(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSequence ALIAS FOR $1;
index 01e0a37..d96f27b 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION copyIncdt(INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pparentid   ALIAS FOR $1;
index a875421..af28d27 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION copyInvoice(INTEGER, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pInvcheadid ALIAS FOR $1;
index d6288a8..30c2d05 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION copyItem(INTEGER, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSItemid ALIAS FOR $1;
@@ -89,7 +89,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION copyItem(INTEGER, TEXT, BOOLEAN, BOOLEAN, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSItemid ALIAS FOR $1;
@@ -104,7 +104,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION copyItem(INTEGER, TEXT, BOOLEAN, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSItemid      ALIAS FOR $1;
@@ -139,7 +139,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION copyItem(INTEGER, TEXT, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSItemid ALIAS FOR $1;
index 906df6f..f03a3c4 100644 (file)
@@ -1,6 +1,20 @@
-DROP FUNCTION IF EXISTS copyitemsite(integer, integer);
-CREATE OR REPLACE FUNCTION copyItemSite(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION copyItemSite(pitemsiteid INTEGER,
+                                        pdestwhsid INTEGER) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
+-- See www.xtuple.com/CPAL for the full text of the software license.
+
+BEGIN
+
+  RETURN copyItemSite(pitemsiteid, pdestwhsid, NULL);
+
+END;
+$$ LANGUAGE 'plpgsql';
+
+
+CREATE OR REPLACE FUNCTION copyItemSite(pitemsiteid INTEGER,
+                                        pdestwhsid INTEGER,
+                                        pdestitemid INTEGER) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pitemsiteid  ALIAS FOR $1;
@@ -33,7 +47,7 @@ BEGIN
 
   SELECT itemsite_id INTO _new.itemsite_id
   FROM itemsite
-  WHERE ((itemsite_item_id=_new.itemsite_item_id)
+  WHERE ((itemsite_item_id=COALESCE(pdestitemid, _new.itemsite_item_id))
     AND  (itemsite_warehous_id=pdestwhsid OR
          (itemsite_warehous_id IS NULL AND pdestwhsid IS NULL)));
   IF (FOUND) THEN
@@ -111,7 +125,7 @@ BEGIN
     itemsite_autoreg,
     itemsite_planning_type,             itemsite_supply_itemsite_id
   ) VALUES (
-    _new.itemsite_id,                  _new.itemsite_item_id,
+    _new.itemsite_id,                  COALESCE(pdestitemid, _new.itemsite_item_id),
     _new.itemsite_warehous_id,         _new.itemsite_qtyonhand,
     _new.itemsite_costmethod,           _new.itemsite_value,
     _new.itemsite_reorderlevel,                _new.itemsite_ordertoqty,
index f89dfa4..472668a 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION copyLocale(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pLocaleid ALIAS FOR $1;
index fe59506..f89474b 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION copyPO(INTEGER, INTEGER, DATE, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSrcid               ALIAS FOR $1;
index 93010a2..e098865 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION copypricingschedule(pIpsheadId INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _ipsheadid INTEGER;
index fbd4076..9e60f19 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION copyPrj(INTEGER, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pparentid   ALIAS FOR $1;
index 14c52f9..0dbd62f 100644 (file)
@@ -1,12 +1,15 @@
-
-CREATE OR REPLACE FUNCTION copyProject(INTEGER, TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION copyproject(integer, text, text, date)
+  RETURNS integer AS
+$BODY$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPrjId ALIAS FOR $1;
   pPrjNumber ALIAS FOR $2;
-  pDueDateOffset ALIAS FOR $3;
+  pPrjName ALIAS FOR $3;
+  pDueDate ALIAS FOR $4;
   _prjid INTEGER;
+  _offset INTEGER;
 
 BEGIN
 
@@ -14,6 +17,10 @@ BEGIN
     RETURN -1;
   END IF;
 
+  IF (COALESCE(pPrjName, '') = '') THEN
+    RETURN -1;
+  END IF;
+
   IF (EXISTS(SELECT prj_id FROM prj WHERE UPPER(prj_number)=UPPER(pPrjNumber))) THEN
     RETURN -2;
   END IF;
@@ -22,6 +29,14 @@ BEGIN
     RETURN -3;
   END IF;
 
+  IF (pDueDate IS NULL) THEN
+    RETURN -4;
+  END IF;
+
+  SELECT (pDueDate - prj_due_date) INTO _offset
+   FROM prj
+   WHERE (prj_id=pPrjId);
+
   SELECT NEXTVAL('prj_prj_id_seq') INTO _prjid;
 
   INSERT INTO prj
@@ -32,11 +47,11 @@ BEGIN
     prj_due_date, prj_assigned_date, prj_completed_date,
     prj_username, prj_recurring_prj_id,
     prj_crmacct_id, prj_cntct_id )
-  SELECT _prjid, UPPER(pPrjNumber), prj_name,
+  SELECT _prjid, UPPER(pPrjNumber), pPrjName,
          prj_descrip, 'P',
          prj_so, prj_wo, prj_po,
          prj_owner_username, NULL,
-         (prj_due_date + COALESCE(pDueDateOffset, 0)),
+         (prj_due_date + COALESCE(_offset, 0)),
          CASE WHEN (prj_username IS NULL) THEN NULL ELSE CURRENT_DATE END, NULL,
          prj_username, prj_recurring_prj_id,
          prj_crmacct_id, prj_cntct_id
@@ -56,7 +71,7 @@ BEGIN
          prjtask_hours_budget, 0.0,
          prjtask_exp_budget, 0.0,
          prjtask_owner_username, NULL,
-         (prjtask_due_date + COALESCE(pDueDateOffset, 0)),
+         (prjtask_due_date + COALESCE(_offset, 0)),
          CASE WHEN (prjtask_username IS NULL) THEN NULL ELSE CURRENT_DATE END,
          NULL, prjtask_username
   FROM prjtask
@@ -76,5 +91,8 @@ BEGIN
   RETURN _prjid;
 
 END;
-$$ LANGUAGE 'plpgsql';
-
+$BODY$
+  LANGUAGE plpgsql VOLATILE
+  COST 100;
+ALTER FUNCTION copyproject(integer, text, text, date)
+  OWNER TO admin;
index 5fda08a..ea27cd3 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION copyQuote(INTEGER, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pQuheadid ALIAS FOR $1;
index 19f9644..afdcd17 100644 (file)
@@ -1,6 +1,6 @@
 CREATE OR REPLACE FUNCTION copySo(pSoheadid INTEGER,
                                   pSchedDate DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _soheadid INTEGER;
index 0ab82c1..e283372 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION copyTodoitem(INTEGER, DATE, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pparentid   ALIAS FOR $1;
@@ -40,9 +40,9 @@ BEGIN
                    CAST(alarm_time - DATE_TRUNC('day',alarm_time) AS TIME),
                    alarm_time_offset,
                    alarm_time_qualifier,
-                   alarm_event, alarm_event_recipient,
-                   alarm_email, alarm_email_recipient,
-                   alarm_sysmsg, alarm_sysmsg_recipient,
+                   (alarm_event_recipient IS NOT NULL), alarm_event_recipient,
+                   (alarm_email_recipient IS NOT NULL AND fetchMetricBool('EnableBatchManager')), alarm_email_recipient,
+                   (alarm_sysmsg_recipient IS NOT NULL), alarm_sysmsg_recipient,
                    'TODO', _todoitemid, 'CHANGEONE')
     INTO _alarmid
     FROM alarm
index 76b3560..f4b84da 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION copyVoucher(INTEGER, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVoheadid ALIAS FOR $1;
index 88d41cb..48b1302 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION correctPoReceipt(INTEGER, NUMERIC, NUMERIC, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPorecvid ALIAS FOR $1;
@@ -13,7 +13,7 @@ END;
 ' LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION correctPoReceipt(INTEGER, NUMERIC, NUMERIC, INTEGER, INTEGER, DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN correctReceipt(''PO'', $1, $2, $3, $4, $5, $6);
index ab4bce2..8642f1e 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION correctProduction(INTEGER, NUMERIC, BOOLEAN, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RAISE NOTICE 'correctProduction(INTEGER, NUMERIC, BOOLEAN, BOOLEAN) has been deprecated. Use corrrectProduction(INTEGER, NUMERIC, BOOLEAN, INTEGER) or a package-specific version instead.';
@@ -9,7 +9,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION correctProduction(INTEGER, NUMERIC, BOOLEAN, BOOLEAN, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RAISE NOTICE 'correctProduction(INTEGER, NUMERIC, BOOLEAN, BOOLEAN, INTEGER) has been deprecated. Use corrrectProduction(INTEGER, NUMERIC, BOOLEAN, INTEGER) or a package-specific version instead.';
@@ -18,7 +18,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION correctProduction(INTEGER, NUMERIC, BOOLEAN, INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoid          ALIAS FOR $1;
@@ -32,7 +32,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION correctProduction(INTEGER, NUMERIC, BOOLEAN, INTEGER, TIMESTAMP WITH TIME ZONE, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoid          ALIAS FOR $1;
index 99ae8c4..5137f8a 100644 (file)
@@ -5,7 +5,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION correctReceipt(INTEGER, NUMERIC, NUMERIC, INTEGER, INTEGER, DATE, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   precvid              ALIAS FOR $1;
index f3886f2..420c524 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION cosByCustomerValue(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCustid ALIAS FOR $1;
index 8f45905..ac8fa5d 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION costsByCustomerByItemSite(INTEGER, INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCustid ALIAS FOR $1;
index 44f283a..93ac28d 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION costsByCustomerValue(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCustid ALIAS FOR $1;
@@ -31,7 +31,7 @@ END;
 ' LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION costsByCustomerValue(INTEGER, INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCustid ALIAS FOR $1;
@@ -67,7 +67,7 @@ END;
 
 
 CREATE OR REPLACE FUNCTION costsByCustomerValue(INTEGER, INTEGER, TEXT) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCustid ALIAS FOR $1;
index e17b5d9..4119b33 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION createAccountingPeriod(DATE, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pStartDate ALIAS FOR $1;
@@ -14,7 +14,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION createaccountingperiod(DATE, DATE, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pStartDate ALIAS FOR $1;
index 0869201..d80b0bc 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION createAccountingYearPeriod(DATE, DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pStartDate ALIAS FOR $1;
index 5d26caa..aab0823 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION createAPChecks(INTEGER, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RAISE NOTICE 'createAPChecks() is deprecated - use createChecks() instead';
index 1e691a3..cc6b21f 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION createAPCreditMemo(INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVendid ALIAS FOR $1;
@@ -22,7 +22,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION createAPCreditMemo(INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVendid ALIAS FOR $1;
@@ -46,7 +46,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION createAPCreditMemo(INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER, DATE, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVendid ALIAS FOR $1;
@@ -72,7 +72,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION createAPCreditMemo(INTEGER, INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVendid ALIAS FOR $1;
@@ -90,7 +90,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION createAPCreditMemo(INTEGER, INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVendid ALIAS FOR $1;
@@ -109,7 +109,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION createAPCreditMemo(INTEGER, INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER, DATE, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVendid ALIAS FOR $1;
@@ -128,7 +128,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION createAPCreditMemo(INTEGER, INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER, DATE, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVendid ALIAS FOR $1;
@@ -148,7 +148,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION createAPCreditMemo(INTEGER, INTEGER, INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER, DATE, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pId ALIAS FOR $1;
index 26e0db6..f7fa905 100644 (file)
@@ -2,13 +2,13 @@ CREATE OR REPLACE FUNCTION createAPCreditMemoApplication(pSourceApopenId INTEGER
                                                          pTargetApopenId INTEGER,
                                                          pAmount NUMERIC,
                                                          pCurrId INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _apCreditApplyId     INTEGER;
 
 BEGIN
-  IF (pAmount > (SELECT currToCurr(apopen_curr_id, pCurrId, ROUND(apopen_amount - apopen_paid, 2), apopen_docdate)
+  IF (pAmount > (SELECT ROUND(currToCurr(apopen_curr_id, pCurrId, (apopen_amount - apopen_paid), apopen_docdate), 2)
                  FROM apopen
                  WHERE (apopen_id=pTargetApopenId))) THEN
     RETURN -1;
index a6860a2..c3f9db7 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION createAPDebitMemo(INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVendid ALIAS FOR $1;
@@ -22,7 +22,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION createAPDebitMemo(INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVendid ALIAS FOR $1;
@@ -46,7 +46,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION createAPDebitMemo(INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER, DATE, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVendid ALIAS FOR $1;
@@ -72,7 +72,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION createAPDebitMemo(INTEGER, INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVendid ALIAS FOR $1;
@@ -92,7 +92,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION createAPDebitMemo(INTEGER, INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVendid ALIAS FOR $1;
@@ -111,7 +111,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION createAPDebitMemo(INTEGER, INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER, DATE, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVendid ALIAS FOR $1;
@@ -131,7 +131,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION createAPDebitMemo(INTEGER, INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER, DATE, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVendid ALIAS FOR $1;
@@ -153,7 +153,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION createAPDebitMemo(INTEGER, INTEGER, INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER, DATE, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pId ALIAS FOR $1;
index d1dc6d5..175045b 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION createAPDiscount(INTEGER, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pApopenid ALIAS FOR $1;
@@ -16,7 +16,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION createAPDiscount(INTEGER, INTEGER, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pApopenid ALIAS FOR $1;
index ff7d7c7..1375b98 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION createARCashDeposit(INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCustid ALIAS FOR $1;
index d426198..14a0763 100644 (file)
@@ -16,7 +16,7 @@ CREATE OR REPLACE FUNCTION createARCreditMemo(pId            INTEGER,
                                               pCurrId        INTEGER = baseCurrId(),
                                               pArAccntid     INTEGER = NULL,
                                               pCoCcpayId     INTEGER = NULL) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _accntid        INTEGER;
@@ -159,7 +159,7 @@ BEGIN
     pDocDate, '',
     pOrderNumber, '', pDocDate,
     'C', pDocNumber, pDocDate,
-    1, (pAmount - _taxBaseValue) * -1, 0,
+    1, (pAmount + _taxBaseValue) * -1, 0, -- taxBaseValue is negative, so we add
     CASE WHEN pSalesrepid < 0 THEN NULL ELSE pSalesrepid END,
     (pCommissiondue * -1.0), FALSE,
     pCurrId, _glSequence, pCoCcpayId)
index 6b6680b..a0151ea 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION createARDebitMemo(INTEGER, INTEGER, INTEGER, TEXT, TEXT, DATE, NUMERIC, TEXT, INTEGER, INTEGER, INTEGER, DATE, INTEGER, INTEGER, NUMERIC, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pId                  ALIAS FOR $1;
index 4c3eddd..552d1c7 100644 (file)
@@ -1,7 +1,7 @@
 CREATE OR REPLACE FUNCTION createbillingheader(integer)
   RETURNS integer AS
 $BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSoheadid            ALIAS FOR $1;
index 0c0a68d..026d553 100644 (file)
@@ -4,7 +4,7 @@ CREATE OR REPLACE FUNCTION createBOMItem( INTEGER, INTEGER, INTEGER, INTEGER, CH
                                           BOOL, INTEGER, BOOL, TEXT, CHAR, INTEGER,
                                           INTEGER, TEXT, TEXT, TEXT )
                            RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pBomitemid ALIAS FOR $1;
@@ -39,19 +39,15 @@ BEGIN
   END IF;
 
 --  Make sure that the parent is not used in the component at some level
-  IF ( SELECT (item_type IN ('M', 'F'))
-       FROM item
-       WHERE (item_id=pComponentItemid) ) THEN
-    SELECT indentedWhereUsed(pParentItemid) INTO _bomworksetid;
-    SELECT bomwork_id INTO _temp
-    FROM bomwork
-    WHERE ( (bomwork_set_id=_bomworksetid)
-     AND (bomwork_item_id=pComponentItemid) )
-    LIMIT 1;
-    IF (FOUND) THEN
-      PERFORM deleteBOMWorkset(_bomworksetid);
-      RETURN -2;
-    END IF;
+  SELECT indentedWhereUsed(pParentItemid) INTO _bomworksetid;
+  SELECT bomwork_id INTO _temp
+  FROM bomwork
+  WHERE ( (bomwork_set_id=_bomworksetid)
+   AND (bomwork_item_id=pComponentItemid) )
+  LIMIT 1;
+  IF (FOUND) THEN
+    PERFORM deleteBOMWorkset(_bomworksetid);
+    RETURN -2;
   END IF;
 
   PERFORM deleteBOMWorkset(_bomworksetid);
@@ -88,7 +84,7 @@ CREATE OR REPLACE FUNCTION createBOMItem( INTEGER, INTEGER, INTEGER, INTEGER, CH
                                           BOOL, INTEGER, BOOL, TEXT, CHAR, INTEGER,
                                           INTEGER, TEXT )
                            RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pBomitemid ALIAS FOR $1;
@@ -135,7 +131,7 @@ CREATE OR REPLACE FUNCTION createBOMItem( INTEGER, INTEGER, INTEGER, CHAR,
                                           BOOL, INTEGER, BOOL, TEXT, CHAR(1), INTEGER,
                                           INTEGER, TEXT, TEXT, TEXT )
                            RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pBomitemid ALIAS FOR $1;
index afac771..f077b92 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION createCheck(INTEGER, TEXT, INTEGER, DATE, NUMERIC, INTEGER, INTEGER, INTEGER, TEXT, TEXT, BOOL) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pBankaccntid         ALIAS FOR  $1;
@@ -25,7 +25,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION createCheck(INTEGER, TEXT, INTEGER, DATE, NUMERIC, INTEGER, INTEGER, INTEGER, TEXT, TEXT, BOOL, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pBankaccntid         ALIAS FOR  $1;
index eb176e7..04b516f 100644 (file)
@@ -1,10 +1,8 @@
-DROP FUNCTION IF EXISTS createchecks(integer, date);
-CREATE OR REPLACE FUNCTION createChecks(INTEGER, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION createChecks(pBankaccntid INTEGER,
+                                        pCheckDate DATE) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
-  pBankaccntid ALIAS FOR $1;
-  pCheckDate ALIAS FOR $2;
   _v RECORD;
   _r RECORD;
   _c RECORD;
@@ -27,12 +25,12 @@ BEGIN
                AND (apselect_date <= pCheckDate)) LOOP
 
     -- if we owe this vendor anything (we might not) then create a check
-    IF ((SELECT 
-                SUM(apselect_amount * _check_curr_rate / apopen_curr_rate)          
-        FROM apselect, apopen
-        WHERE ((apselect_apopen_id=apopen_id)
-          AND  (apopen_vend_id=_v.vend_id)
-          AND  (apselect_bankaccnt_id=pBankaccntid)) ) > 0) THEN
+    -- allow $0 checks
+    IF ((SELECT SUM(CASE apopen_doctype WHEN 'C' THEN (apselect_amount * -1.0)
+                                        ELSE apselect_amount END * _check_curr_rate / apopen_curr_rate)          
+        FROM apselect JOIN apopen ON (apopen_id=apselect_apopen_id)
+        WHERE ((apopen_vend_id=_v.vend_id)
+          AND  (apselect_bankaccnt_id=pBankaccntid)) ) >= 0) THEN
       -- 0.01 is a temporary amount; we''ll update the check amount later
       _checkid := createCheck(pBankaccntid,    'V',    _v.vend_id,
                              pCheckDate,               0.01,   _check_curr_id,
@@ -65,8 +63,9 @@ BEGIN
 
       -- one check can pay for purchases on multiple dates in multiple currencies
       UPDATE checkhead
-      SET checkhead_amount = (SELECT SUM(checkitem_amount / checkitem_curr_rate)
-                             FROM checkitem
+      SET checkhead_amount = (SELECT SUM(CASE WHEN (apopen_doctype='C') THEN checkitem_amount / checkitem_curr_rate * -1.0
+                                              ELSE checkitem_amount / checkitem_curr_rate END)
+                             FROM checkitem LEFT OUTER JOIN apopen ON (apopen_id=checkitem_apopen_id)
                              WHERE (checkitem_checkhead_id=checkhead_id))
       WHERE (checkhead_id=_checkid);
 
index 6f61da9..715bb30 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION createCountTag(int, text, bool, bool) RETURNS integer AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
@@ -14,7 +14,7 @@ $$ LANGUAGE 'plpgsql';
 CREATE OR REPLACE FUNCTION createcounttag(integer, text, boolean, boolean, integer)
   RETURNS integer AS $$
 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index 9e676ee..8f4f5c0 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION createCycleCountsByWarehouse(INTEGER, INTEGER, TEXT, BOOLEAN, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWarehousid ALIAS FOR $1;
@@ -16,7 +16,7 @@ END;
 
 CREATE OR REPLACE FUNCTION createcyclecountsbywarehouse(integer, integer, text, boolean, boolean, integer, boolean)
   RETURNS integer AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWarehousid ALIAS FOR $1;
@@ -87,7 +87,7 @@ END;
 ' LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION createCycleCountsByWarehouse(INTEGER, INTEGER, INTEGER, TEXT, BOOLEAN, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWarehousid ALIAS FOR $1;
@@ -102,7 +102,7 @@ END;
 ' LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION createCycleCountsByWarehouse(INTEGER, TEXT, INTEGER, TEXT, BOOLEAN, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWarehousid ALIAS FOR $1;
index 694a8e9..010221d 100644 (file)
@@ -1,6 +1,6 @@
 CREATE OR REPLACE FUNCTION createcyclecountsbywarehousebyclasscode(integer, integer, integer, text, boolean, boolean, integer, boolean)
   RETURNS integer AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWarehousid ALIAS FOR $1;
@@ -74,7 +74,7 @@ END;
 
 CREATE OR REPLACE FUNCTION createcyclecountsbywarehousebyclasscode(integer, text, integer, text, boolean, boolean, integer, boolean)
   RETURNS integer AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWarehousid ALIAS FOR $1;
index c7d2fd4..4bea7c2 100644 (file)
@@ -1,6 +1,6 @@
 CREATE OR REPLACE FUNCTION createcyclecountsbywarehousebyplannercode(integer, integer, integer, text, boolean, boolean, integer, boolean)
   RETURNS integer AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWarehousid ALIAS FOR $1;
@@ -73,7 +73,7 @@ END;
 
 CREATE OR REPLACE FUNCTION createcyclecountsbywarehousebyplannercode(integer, text, integer, text, boolean, boolean, integer, boolean)
   RETURNS integer AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWarehousid ALIAS FOR $1;
index c1ade99..c03cf0d 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION createInvoice(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCobmiscid ALIAS FOR $1;
@@ -68,6 +68,15 @@ BEGIN
        WHERE taxhist_parent_id = pCobmiscid 
        AND taxhist_taxtype_id = getadjustmenttaxtypeid();
 
+--  Create the Invoice Characteristic Assignments
+    INSERT INTO charass
+          (charass_target_type, charass_target_id, charass_char_id, charass_value, charass_default, charass_price)
+    SELECT 'INV', _invcheadid, charass_char_id, charass_value, charass_default, charass_price
+      FROM cobmisc JOIN cohead ON (cohead_id=cobmisc_cohead_id)
+                   JOIN charass ON ((charass_target_type='SO') AND (charass_target_id=cohead_id))
+                   JOIN char ON (char_id=charass_char_id AND char_invoices)
+    WHERE (cobmisc_id=pCobmiscid);
+
 --  Create the Invoice items
   FOR _r IN SELECT coitem_id, coitem_linenumber, coitem_subnumber, coitem_custpn,
                    coitem_qtyord, cobill_qty,
index cd670c2..7afeaac 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION createInvoiceConsolidated(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCustid ALIAS FOR $1;
index 390213a..136de7e 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION createInvoices() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _counter INTEGER;
@@ -24,7 +24,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION createInvoices(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN createinvoices($1, false);
@@ -32,7 +32,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION createInvoices(INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCustTypeId ALIAS FOR $1;
index 04454cf..672ee36 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION createMiscAPCheck(INTEGER, INTEGER, DATE, NUMERIC, INTEGER, TEXT, TEXT) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RAISE NOTICE ''createMiscAPCheck() is deprecated - use createCheck() instead'';
@@ -9,7 +9,7 @@ END;
 
 
 CREATE OR REPLACE FUNCTION createMiscAPCheck(INTEGER, INTEGER, DATE, NUMERIC, INTEGER, INTEGER, TEXT, TEXT) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RAISE NOTICE ''createMiscAPCheck() is deprecated - use createCheck() instead'';
index 458d1bc..5a1a013 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION createPkgSchema(TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pname         ALIAS FOR $1;
index 34450fe..74ac8b6 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION createPr(INTEGER, INTEGER, NUMERIC, DATE, TEXT, CHARACTER(1), INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pOrderNumber ALIAS FOR $1;
@@ -30,7 +30,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION createPr(INTEGER, INTEGER, NUMERIC, DATE, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pOrderNumber ALIAS FOR $1;
@@ -59,7 +59,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION createPr(INTEGER, CHAR, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pOrderNumber ALIAS FOR $1;
@@ -131,7 +131,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION createPr(CHAR, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pParentType ALIAS FOR $1;
@@ -172,7 +172,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION createpr(INTEGER, CHARACTER, INTEGER, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pOrderNumber ALIAS FOR $1;
index 1d6754c..0fc9095 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION createPriv(text, text, text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pModule ALIAS FOR $1;
index 4a9caa7..db45cc0 100644 (file)
@@ -3,7 +3,7 @@ SELECT dropIfExists('FUNCTION', 'createPurchaseToSale(integer, integer, boolean,
 SELECT dropIfExists('FUNCTION', 'createPurchaseToSale(integer, integer, boolean, numeric, date, numeric)', 'fixcountry');
 
 CREATE OR REPLACE FUNCTION createPurchaseToSale(INTEGER, INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCoitemId ALIAS FOR $1;
@@ -19,7 +19,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION createPurchaseToSale(INTEGER, INTEGER, BOOLEAN, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCoitemId ALIAS FOR $1;
@@ -36,7 +36,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION createPurchaseToSale(INTEGER, INTEGER, BOOLEAN, NUMERIC, DATE, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCoitemId ALIAS FOR $1;
@@ -72,49 +72,57 @@ BEGIN
   SELECT *,
          COALESCE(roundQty(item_fractional, (coitem_qtyord * coitem_qty_invuomratio)), 0.0) AS orderqty
   INTO _s
-  FROM cohead JOIN coitem ON (cohead_id = coitem_cohead_id)
-    LEFT OUTER JOIN shiptoinfo ON (cohead_shipto_id = shipto_id)
-    LEFT OUTER JOIN itemsite ON (coitem_itemsite_id = itemsite_id)
-    LEFT OUTER JOIN item ON (item_id = itemsite_item_id)
+  FROM coitem JOIN cohead ON (cohead_id = coitem_cohead_id)
+              LEFT OUTER JOIN shiptoinfo ON (cohead_shipto_id = shipto_id)
+              LEFT OUTER JOIN addr ON (shipto_addr_id = addr_id)
+              LEFT OUTER JOIN cntct ON (shipto_cntct_id = cntct_id)
+              LEFT OUTER JOIN itemsite ON (coitem_itemsite_id = itemsite_id)
+              LEFT OUTER JOIN item ON (item_id = itemsite_item_id)
   WHERE (coitem_id = pCoitemId);
   IF (NOT FOUND) THEN
     RETURN -1;
   END IF;
 
   SELECT * INTO _w
-  FROM whsinfo JOIN addr ON (warehous_addr_id = addr_id)
-    JOIN cntct ON (warehous_cntct_id = cntct_id)
-    JOIN itemsite ON (warehous_id = itemsite_warehous_id)
+  FROM itemsite JOIN whsinfo ON (warehous_id = itemsite_warehous_id)
+                LEFT OUTER JOIN addr ON (warehous_addr_id = addr_id)
+                LEFT OUTER JOIN cntct ON (warehous_cntct_id = cntct_id)
   WHERE (itemsite_id = _s.itemsite_id);
 
   SELECT * INTO _i
   FROM itemsrc JOIN vendinfo ON (itemsrc_vend_id = vend_id)
-    LEFT OUTER JOIN cntct ON (vend_cntct1_id = cntct_id)
-    LEFT OUTER JOIN addr ON (vend_addr_id = addr_id)
+               LEFT OUTER JOIN cntct ON (vend_cntct1_id = cntct_id)
+               LEFT OUTER JOIN addr ON (vend_addr_id = addr_id)
   WHERE (itemsrc_id = pItemSourceId);
   IF (NOT FOUND) THEN
     RETURN -2;
   END IF;
 
-  SELECT * INTO _shipto
-  FROM shiptoinfo JOIN cntct ON (shipto_cntct_id = cntct_id)
-    JOIN addr ON (shipto_addr_id = addr_id)
-    RIGHT OUTER JOIN cohead ON (cohead_cust_id = shipto_cust_id)
-  WHERE (cohead_id = _s.cohead_id)
-  LIMIT 1;
-
   IF (pDropShip) THEN
     SELECT COALESCE(pohead_id, -1) INTO _temp
     FROM pohead
     WHERE ( (pohead_status = 'U')
       AND (pohead_vend_id = _i.itemsrc_vend_id)
-      AND (pohead_shiptoaddress_id = _s.shipto_addr_id) );
+      AND (pohead_shiptoname = COALESCE(_s.cohead_shiptoname, _s.shipto_name, ''))
+      AND (pohead_shiptoaddress1 = COALESCE(_s.cohead_shiptoaddress1, _s.addr_line1, ''))
+      AND (pohead_shiptoaddress2 = COALESCE(_s.cohead_shiptoaddress2, _s.addr_line2, ''))
+      AND (pohead_shiptoaddress3 = COALESCE(_s.cohead_shiptoaddress3, _s.addr_line3, ''))
+      AND (pohead_shiptocity = COALESCE(_s.cohead_shiptocity, _s.addr_city, ''))
+      AND (pohead_shiptostate = COALESCE(_s.cohead_shiptostate, _s.addr_state, ''))
+      AND (pohead_shiptozipcode = COALESCE(_s.cohead_shiptozipcode, _s.addr_postalcode, ''))
+      AND (pohead_shiptocountry = COALESCE(_s.cohead_shiptocountry, _s.addr_country, '')) );
   ELSE
     SELECT COALESCE(pohead_id, -1) INTO _temp
     FROM pohead
     WHERE ( (pohead_status = 'U')
       AND (pohead_vend_id = _i.itemsrc_vend_id)
-      AND (pohead_shiptoaddress_id = _w.addr_id) );
+      AND (pohead_shiptoaddress1 = COALESCE(_w.addr_line1, ''))
+      AND (pohead_shiptoaddress2 = COALESCE(_w.addr_line2, ''))
+      AND (pohead_shiptoaddress3 = COALESCE(_w.addr_line3, ''))
+      AND (pohead_shiptocity = COALESCE(_w.addr_city, ''))
+      AND (pohead_shiptostate = COALESCE(_w.addr_state, ''))
+      AND (pohead_shiptozipcode = COALESCE(_w.addr_postalcode, ''))
+      AND (pohead_shiptocountry = COALESCE(_w.addr_country, '')) );
   END IF;
 
   IF (FOUND) THEN
@@ -138,6 +146,7 @@ BEGIN
           pohead_shipto_cntct_suffix, pohead_shipto_cntct_phone,
           pohead_shipto_cntct_title, pohead_shipto_cntct_fax, 
           pohead_shipto_cntct_email, pohead_shiptoaddress_id,
+          pohead_shiptoname,
           pohead_shiptoaddress1,
           pohead_shiptoaddress2,
           pohead_shiptoaddress3,
@@ -157,18 +166,19 @@ BEGIN
           getEffectiveXtUser(), _i.itemsrc_vend_id, _i.vend_taxzone_id,
          CURRENT_DATE, COALESCE(_i.vend_curr_id, basecurrid()), _s.cohead_id,
           COALESCE(_s.cohead_warehous_id, -1), COALESCE(_i.vend_shipvia, TEXT('')),
-          COALESCE(_i.vend_terms_id, -1), COALESCE(_s.cohead_shipto_cntct_id, _shipto.shipto_cntct_id),
-          COALESCE(_s.cohead_shipto_cntct_honorific, _shipto.cntct_honorific), COALESCE(_s.cohead_shipto_cntct_first_name, _shipto.cntct_first_name),
-          COALESCE(_s.cohead_shipto_cntct_middle, _shipto.cntct_middle), COALESCE(_s.cohead_shipto_cntct_last_name, _shipto.cntct_last_name),
-          COALESCE(_s.cohead_shipto_cntct_suffix, _shipto.cntct_suffix), COALESCE(_s.cohead_shipto_cntct_phone, _shipto.cntct_phone),
-          COALESCE(_s.cohead_shipto_cntct_title, _shipto.cntct_title), COALESCE(_s.cohead_shipto_cntct_fax, _shipto.cntct_fax),
-          COALESCE(_s.cohead_shipto_cntct_email, _shipto.cntct_email), COALESCE(_s.shipto_addr_id, _shipto.addr_id),
-          COALESCE(_s.cohead_shiptoaddress1, _shipto.addr_line1),
-          COALESCE(_s.cohead_shiptoaddress2, _shipto.addr_line2),
-          COALESCE(_s.cohead_shiptoaddress3, _shipto.addr_line3),
-          COALESCE(_s.cohead_shiptocity, _shipto.addr_city),
-          COALESCE(_s.cohead_shiptostate, _shipto.addr_state), COALESCE(_s.cohead_shiptozipcode, _shipto.addr_postalcode),
-          COALESCE(_s.cohead_shiptocountry, _shipto.addr_country), _i.cntct_id,
+          COALESCE(_i.vend_terms_id, -1), COALESCE(_s.cohead_shipto_cntct_id, _s.shipto_cntct_id),
+          COALESCE(_s.cohead_shipto_cntct_honorific, _s.cntct_honorific), COALESCE(_s.cohead_shipto_cntct_first_name, _s.cntct_first_name),
+          COALESCE(_s.cohead_shipto_cntct_middle, _s.cntct_middle), COALESCE(_s.cohead_shipto_cntct_last_name, _s.cntct_last_name),
+          COALESCE(_s.cohead_shipto_cntct_suffix, _s.cntct_suffix), COALESCE(_s.cohead_shipto_cntct_phone, _s.cntct_phone),
+          COALESCE(_s.cohead_shipto_cntct_title, _s.cntct_title), COALESCE(_s.cohead_shipto_cntct_fax, _s.cntct_fax),
+          COALESCE(_s.cohead_shipto_cntct_email, _s.cntct_email), COALESCE(_s.shipto_addr_id, _s.addr_id),
+          COALESCE(_s.cohead_shiptoname, _s.shipto_name, ''),
+          COALESCE(_s.cohead_shiptoaddress1, _s.addr_line1, ''),
+          COALESCE(_s.cohead_shiptoaddress2, _s.addr_line2, ''),
+          COALESCE(_s.cohead_shiptoaddress3, _s.addr_line3, ''),
+          COALESCE(_s.cohead_shiptocity, _s.addr_city, ''),
+          COALESCE(_s.cohead_shiptostate, _s.addr_state, ''), COALESCE(_s.cohead_shiptozipcode, _s.addr_postalcode, ''),
+          COALESCE(_s.cohead_shiptocountry, _s.addr_country, ''), _i.cntct_id,
           COALESCE(_i.cntct_honorific, TEXT('')), COALESCE(_i.cntct_first_name, TEXT('')),
           COALESCE(_i.cntct_middle, TEXT('')), COALESCE(_i.cntct_last_name, TEXT('')),
           COALESCE(_i.cntct_suffix, TEXT('')), COALESCE(_i.cntct_phone, TEXT('')),
@@ -214,12 +224,12 @@ BEGIN
           _w.cntct_suffix, _w.cntct_phone,
           _w.cntct_title, _w.cntct_fax,
           _w.cntct_email, _w.addr_id,
-          _w.addr_line1,
-          _w.addr_line2,
-          _w.addr_line3,
-          _w.addr_city,
-          _w.addr_state, _w.addr_postalcode,
-          _w.addr_country, _i.cntct_id,
+          COALESCE(_w.addr_line1, ''),
+          COALESCE(_w.addr_line2, ''),
+          COALESCE(_w.addr_line3, ''),
+          COALESCE(_w.addr_city, ''),
+          COALESCE(_w.addr_state, ''), COALESCE(_w.addr_postalcode, ''),
+          COALESCE(_w.addr_country, ''), _i.cntct_id,
           COALESCE(_i.cntct_honorific, TEXT('')), COALESCE(_i.cntct_first_name, TEXT('')),
           COALESCE(_i.cntct_middle, TEXT('')), COALESCE(_i.cntct_last_name, TEXT('')),
           COALESCE(_i.cntct_suffix, TEXT('')), COALESCE(_i.cntct_phone, TEXT('')),
@@ -242,8 +252,12 @@ BEGIN
   WHERE (itemtax_item_id = _i.itemsrc_item_id);
 
   IF (pPrice IS NULL) THEN
-    SELECT itemsrcPrice(pItemSourceId, COALESCE(_s.cohead_warehous_id, -1), pDropShip,
-                        COALESCE(pQty, _s.orderqty), COALESCE(_i.vend_curr_id, baseCurrId()), CURRENT_DATE) INTO _price;
+    SELECT itemsrcPrice(pItemSourceId,
+                        COALESCE(_s.cohead_warehous_id, -1),
+                        pDropShip,
+                        (COALESCE(pQty, _s.orderqty) / COALESCE(_i.itemsrc_invvendoruomratio, 1.00)),
+                        COALESCE(_i.vend_curr_id, baseCurrId()),
+                        CURRENT_DATE) INTO _price;
   ELSE
     _price := pPrice;
   END IF;
@@ -278,7 +292,7 @@ BEGIN
         poitem_unitprice, poitem_vend_item_number, 
         poitem_itemsrc_id, poitem_order_id, poitem_order_type, poitem_prj_id, poitem_stdcost, 
         poitem_manuf_name, poitem_manuf_item_number, 
-        poitem_manuf_item_descrip, poitem_taxtype_id )
+        poitem_manuf_item_descrip, poitem_taxtype_id, poitem_comments )
     VALUES
       ( _poitemid, 'U', _poheadid, _polinenumber,
         COALESCE(pDueDate, _s.coitem_scheddate), _s.coitem_itemsite_id,
@@ -287,7 +301,8 @@ BEGIN
         _price, COALESCE(_i.itemsrc_vend_item_number, TEXT('')),
         pItemSourceId, pCoitemId, 'S', _s.cohead_prj_id, stdcost(_i.itemsrc_item_id),
         COALESCE(_i.itemsrc_manuf_name, TEXT('')), COALESCE(_i.itemsrc_manuf_item_number, TEXT('')),
-        COALESCE(_i.itemsrc_manuf_item_descrip, TEXT('')), _taxtypeid );
+        COALESCE(_i.itemsrc_manuf_item_descrip, TEXT('')), _taxtypeid,
+        COALESCE(_s.coitem_memo, TEXT('')));
   END IF;
   -- Copy characteristics from the coitem to the poitem
   INSERT INTO charass
@@ -305,21 +320,15 @@ BEGIN
   WHERE ( coitem_id = pCoitemId );
 
   -- Generate the PoItemCreatedBySo event notice
-  INSERT INTO evntlog
-              ( evntlog_evnttime, evntlog_username, evntlog_evnttype_id,
-                evntlog_ordtype, evntlog_ord_id, evntlog_warehous_id,
-                evntlog_number )
-  SELECT CURRENT_TIMESTAMP, evntnot_username, evnttype_id ,
-         'P', poitem_id, itemsite_warehous_id,
-         (pohead_number || '-' || poitem_linenumber || ': ' || item_number)
-  FROM evntnot JOIN evnttype ON (evntnot_evnttype_id=evnttype_id)
-       JOIN itemsite ON (evntnot_warehous_id=itemsite_warehous_id)
-       JOIN item ON (itemsite_item_id=item_id)
-       JOIN poitem ON (poitem_itemsite_id=itemsite_id)
-       JOIN pohead ON (poitem_pohead_id=pohead_id)
-  WHERE ( (poitem_id=_poitemid)
-    AND (poitem_duedate <= (CURRENT_DATE + itemsite_eventfence))
-    AND (evnttype_name='PoItemCreatedBySo') );
+  PERFORM postEvent('PoItemCreatedBySo', 'P', poitem_id,
+                    itemsite_warehous_id,
+                    (pohead_number || '-'|| poitem_linenumber || ': ' || item_number),
+                    NULL, NULL, NULL, NULL)
+  FROM poitem JOIN pohead ON (pohead_id=poitem_pohead_id)
+              JOIN itemsite ON (itemsite_id=poitem_itemsite_id)
+              JOIN item ON (item_id=itemsite_item_id)
+  WHERE (poitem_id=_poitemid)
+    AND (poitem_duedate <= (CURRENT_DATE + itemsite_eventfence));
 
   RETURN _poitemid;
 
index 4db87e5..eb3a95b 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION createRecurringInvoices() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RAISE NOTICE 'createRecurringInvoices() has been deprecated; use createRecurringItems(NULL, ''I'') instead.';
index 50e3937..cd13624 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION createRecurringItems(INTEGER, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pParentid  ALIAS FOR $1;      -- if NULL then all items with the given pType
index d366a47..1a341c1 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION createTodoItem(INTEGER, TEXT, TEXT, TEXT, INTEGER, INTEGER, INTEGER, DATE, DATE, CHARACTER(1), DATE, DATE, INTEGER, TEXT, TEXT) RETURNS INTEGER AS $$  
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN createTodoItem($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, NULL);
@@ -9,7 +9,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION createTodoItem(INTEGER, TEXT, TEXT, TEXT, INTEGER, INTEGER, INTEGER, DATE, DATE, CHARACTER(1), DATE, DATE, INTEGER, TEXT, TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   ptodoid     ALIAS FOR  $1;
index 9206ca3..7d6abe8 100644 (file)
@@ -1,6 +1,6 @@
 DROP FUNCTION IF EXISTS createUser(TEXT, BOOLEAN);
 CREATE OR REPLACE FUNCTION createUser(pUsername TEXT, pCreateUsers BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   IF (pCreateUsers) THEN
index 7809cf2..9b92037 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION createWo(INTEGER, INTEGER, INTEGER, NUMERIC, INTEGER, DATE, TEXT, CHAR, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoNumber ALIAS FOR $1;
@@ -21,7 +21,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION createWo(INTEGER, INTEGER, INTEGER, NUMERIC, INTEGER, DATE, TEXT, CHAR, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoNumber ALIAS FOR $1;
@@ -43,7 +43,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION createWo(INTEGER, INTEGER, INTEGER, NUMERIC, INTEGER, DATE, TEXT, CHAR, INTEGER, INTEGER, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoNumber ALIAS FOR $1;
@@ -68,7 +68,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION createWo(INTEGER, INTEGER, INTEGER, NUMERIC, DATE, DATE, TEXT, CHAR, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoNumber ALIAS FOR $1;
@@ -105,7 +105,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION createWo(INTEGER, INTEGER, INTEGER, NUMERIC, DATE, DATE, TEXT, CHAR, INTEGER, INTEGER, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoNumber ALIAS FOR $1;
@@ -128,7 +128,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION createWo(INTEGER, INTEGER, INTEGER, NUMERIC, DATE, DATE, TEXT, CHAR, INTEGER, INTEGER, INTEGER, INTEGER, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoNumber ALIAS FOR $1;
@@ -226,7 +226,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION createWo(INTEGER, INTEGER, NUMERIC, INTEGER, DATE, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoNumber ALIAS FOR $1;
@@ -245,7 +245,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION createWo(INTEGER, INTEGER, NUMERIC, INTEGER, DATE, TEXT, CHAR, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoNumber ALIAS FOR $1;
@@ -266,7 +266,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION createWo(INTEGER, INTEGER, NUMERIC, DATE, DATE, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoNumber ALIAS FOR $1;
index b7557dc..4875ebc 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION createWoMaterial(INTEGER, INTEGER, char(1), NUMERIC, NUMERIC, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoid ALIAS FOR $1;
@@ -19,7 +19,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION createWoMaterial(INTEGER, INTEGER, char(1), INTEGER, NUMERIC, NUMERIC, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoid ALIAS FOR $1;
@@ -40,7 +40,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION createWoMaterial(INTEGER, INTEGER, char(1), INTEGER, NUMERIC, NUMERIC, NUMERIC, INTEGER, TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoid ALIAS FOR $1;
@@ -75,7 +75,45 @@ CREATE OR REPLACE FUNCTION createWoMaterial(pWoid INTEGER,
                                             pRef TEXT,
                                             pWooperId INTEGER,
                                             pPickList BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
+-- See www.xtuple.com/CPAL for the full text of the software license.
+DECLARE
+  _womatlid INTEGER;
+
+BEGIN
+
+  SELECT createWoMaterial(pWoid,
+                          pItemsiteid,
+                          pIssueMethod,
+                          pUomId,
+                          pQtyFxd,
+                          pQtyPer,
+                          pScrap,
+                          pBomitemId,
+                          pNotes,
+                          pRef,
+                          pWooperId,
+                          pPickList,
+                          0.0) INTO _womatlid;
+
+  RETURN _womatlid;
+END;
+$$ LANGUAGE 'plpgsql';
+
+CREATE OR REPLACE FUNCTION createWoMaterial(pWoid INTEGER,
+                                            pItemsiteid INTEGER,
+                                            pIssueMethod CHAR(1),
+                                            pUomId INTEGER,
+                                            pQtyFxd NUMERIC,
+                                            pQtyPer NUMERIC,
+                                            pScrap NUMERIC,
+                                            pBomitemId INTEGER,
+                                            pNotes TEXT,
+                                            pRef TEXT,
+                                            pWooperId INTEGER,
+                                            pPickList BOOLEAN,
+                                            pPrice NUMERIC) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _womatlid INTEGER;
@@ -91,13 +129,13 @@ BEGIN
     womatl_qtyper, womatl_scrap, womatl_qtyreq,
     womatl_qtyiss, womatl_qtywipscrap, womatl_wooper_id,
     womatl_bomitem_id, womatl_duedate, womatl_notes,
-    womatl_ref, womatl_picklist )
+    womatl_ref, womatl_picklist, womatl_price )
   SELECT _womatlid, wo_id, pItemsiteid,
          pIssueMethod, pUomId, pQtyFxd,
          pQtyPer, pScrap, roundQty(item_fractional, (pQtyFxd + wo_qtyord * pQtyPer) * (1 + pScrap) ),
          0, 0, COALESCE(pWooperId, -1),
          pBomitemId, wo_startdate, pNotes,
-         pRef, COALESCE(pPickList, item_picklist) 
+         pRef, COALESCE(pPickList, item_picklist), pPrice 
   FROM wo, itemsite JOIN item ON (item_id=itemsite_item_id)
   WHERE ( (wo_id=pWoid)
    AND (itemsite_id=pItemsiteid) );
index 9d22e0d..2bf9bac 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION creditmemototal(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCreditmemoId ALIAS FOR $1;
index f12ed0a..21e7da9 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION crmacct() RETURNS SETOF crmacct AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _row crmacct%ROWTYPE;
index 6defe5e..5dd26a5 100644 (file)
@@ -1,6 +1,6 @@
 CREATE OR REPLACE FUNCTION currConcat(VARCHAR(3), VARCHAR(9))
        RETURNS VARCHAR(15) AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   curr_abbr   ALIAS FOR $1;
@@ -22,7 +22,7 @@ END;
 $$ LANGUAGE plpgsql;
 
 CREATE OR REPLACE FUNCTION currConcat(INTEGER) RETURNS VARCHAR(15) AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   id ALIAS FOR $1;
index 4f7cc91..fb44979 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION currentAPMemoNumber() RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _number INTEGER;
index 29110df..6dff7b1 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION currentARMemoNumber() RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _number INTEGER;
index 0fbe587..6d4f64c 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION currentCashRcptNumber() RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _number INTEGER;
index 6c6717d..2125924 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION currentNumber(TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pName   ALIAS FOR $1;
index 4654077..4956319 100644 (file)
@@ -6,7 +6,7 @@
 -- negative values = a loss.
 CREATE OR REPLACE FUNCTION currGain(INTEGER, NUMERIC, DATE, DATE)
 RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pId ALIAS FOR $1;
index fc67aac..31d4e86 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION currRate(INTEGER, DATE) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN currRate($1, NULL, $2);
@@ -10,7 +10,7 @@ $$ LANGUAGE plpgsql;
 CREATE OR REPLACE FUNCTION currRate(pFromCurr INTEGER,
                                     pToCurr INTEGER,
                                     pDate DATE) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _fromRate NUMERIC := 1.0;
index a0ec22d..90f4ae8 100644 (file)
@@ -6,7 +6,7 @@
 -- curr_rate.  see mantis #3901.
 
 CREATE OR REPLACE FUNCTION currToBase (integer, numeric, date) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pId     ALIAS FOR $1;
index 0bf82f3..50500e1 100644 (file)
@@ -7,7 +7,7 @@
 
 CREATE OR REPLACE FUNCTION currToCurr(INTEGER, INTEGER, NUMERIC, DATE)
     RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pFromCurr ALIAS FOR $1;
index c8c6f28..1db578c 100644 (file)
@@ -6,7 +6,7 @@
 -- curr_rate.  see mantis #3901.
 
 CREATE OR REPLACE FUNCTION currToLocal (integer, numeric, date) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
     pId     ALIAS FOR $1;
index 06aaa59..414649e 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION custitem(cust_id INTEGER, shipto_id INTEGER DEFAULT -1, asof DATE DEFAULT CURRENT_DATE) RETURNS SETOF integer AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
   -- Non Exclusive
index a849f09..5010701 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION customerCanPurchase(INTEGER, INTEGER) RETURNS BOOL AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pitemid ALIAS FOR $1;
@@ -11,7 +11,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION customerCanPurchase(INTEGER, INTEGER, INTEGER) RETURNS BOOL AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pitemid ALIAS FOR $1;
@@ -26,7 +26,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION customerCanPurchase(INTEGER, INTEGER, INTEGER, DATE) RETURNS BOOL AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pitemid ALIAS FOR $1;
index 24a8089..99a2954 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION defaultLocationName(INTEGER) RETURNS TEXT AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index 20b09da..84d6f2b 100644 (file)
@@ -1,7 +1,7 @@
 
 CREATE OR REPLACE FUNCTION deleteAccount(integer) RETURNS integer
     AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pAccntid ALIAS FOR $1;
index b5a0958..f0adf65 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION deleteAccountingPeriod(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPeriodid ALIAS FOR $1;
index 17ec9d0..917ea61 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION deleteAccountingYearPeriod(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPeriodid ALIAS FOR $1;
index ff7b568..e78a655 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION deleteAddress(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   paddrId     ALIAS FOR $1;
index e446a0e..78cc717 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteAPCheck(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RAISE NOTICE ''deleteAPCheck() is deprecated - use deleteCheck() instead'';
index 34b2106..6b7b23f 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION deleteBankAdjustmentType(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pBankadjtypeid ALIAS FOR $1;
index b6d444e..bd5425a 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION deleteBankReconciliation(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pbankrecid    ALIAS FOR $1;
index acee7dd..48e43fe 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deletebom(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index 01054fa..653b017 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteBOMWorkset(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWorksetid ALIAS FOR $1;
index 20aa8cb..b0ded8c 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION deleteBudget(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pBudgheadid ALIAS FOR $1;
index 6f82227..9b9f300 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION deleteBudgetItems(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pBudgheadid ALIAS FOR $1;
index e20033b..dac2326 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteCashrcpt(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pcashrcptid ALIAS FOR $1;
index dc5cb3e..fa0a721 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION deleteCharacteristic(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCharid ALIAS FOR $1;
@@ -37,6 +37,18 @@ BEGIN
       RETURN -6;
     ELSIF (_r.charass_target_type = 'EMP') THEN
       RETURN -7;
+    ELSIF (_r.charass_target_type = 'QU') THEN
+      RETURN -8;
+    ELSIF (_r.charass_target_type = 'SO') THEN
+      RETURN -9;
+    ELSIF (_r.charass_target_type = 'INV') THEN
+      RETURN -10;
+    ELSIF (_r.charass_target_type = 'V') THEN
+      RETURN -11;
+    ELSIF (_r.charass_target_type = 'PO') THEN
+      RETURN -12;
+    ELSIF (_r.charass_target_type = 'VO') THEN
+      RETURN -13;
     ELSE
       RETURN -99;
     END IF;
index 1424db3..ffd9d9d 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteCheck(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCheckid ALIAS FOR $1;
index 1971710..c6188ce 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteClassCode(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pClasscodeid ALIAS FOR $1;
index 34979ea..e89fd56 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteCompany(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pcompanyid ALIAS FOR $1;
index bd9c473..9d6833c 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteCreditMemo(INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCmheadid ALIAS FOR $1;
index 97b2ed6..40e167a 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION deleteCustomer(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCustid ALIAS FOR $1;
index 003bf84..118fabc 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION deleteCustomerType(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCusttypeid ALIAS FOR $1;
index 623441e..735aa0d 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteEmpGrp(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pempgrpid ALIAS FOR $1;
index df2f724..b04e4e5 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteexpiredips() RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _r RECORD;
index 70a3514..8e10837 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteFlgrp(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pFlgrpid ALIAS FOR $1;
index 4d79f20..143b4f7 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION deleteForm(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pFormid ALIAS FOR $1;
index ddf83c7..d832713 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteFreightClass(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pFreightClassid ALIAS FOR $1;
index dbdb47b..97699c3 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteGlSeries(INTEGER, TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSequence ALIAS FOR $1;
index fc38c21..e716f4f 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteIncident(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pincdtid    ALIAS FOR $1;
index 0287028..a1c5a34 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteInvoice(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pInvcheadid ALIAS FOR $1;
@@ -36,6 +36,10 @@ BEGIN
   WHERE (aropenalloc_doctype='I')
     AND (aropenalloc_doc_id=pInvcheadid);
 
+  DELETE FROM charass
+  WHERE (charass_target_type='INV')
+    AND (charass_target_id=pInvcheadid);
+
   DELETE FROM invcitem
   WHERE (invcitem_invchead_id=pInvcheadid);
 
index 1f99772..9f1afb4 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteIpsItem(pIpsItemId INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
 
index fc0e83e..da0fef2 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteIpsProdCat(pIpsItemId INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
 
index 081539e..b4fcb79 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteItem(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index a81803f..408fb5c 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteItemCost(INTEGER, INTEGER) RETURNS INTEGER AS $BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemId ALIAS FOR $1;
index 0365d3e..c4b42cd 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteItemSite(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index 6534c51..8e227d0 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteItemUOM(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemuomid ALIAS FOR $1;
index da09d02..11c773a 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteItemUOMConv(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemuomconvid ALIAS FOR $1;
index 98b5c4e..d8949cd 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteLocation(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pLocationid ALIAS FOR $1;
index 1337453..521d78a 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteMetaSQL(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pid ALIAS FOR $1;
index 132b9b0..adc38fa 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteOpenRecurringItems(INTEGER, TEXT, TIMESTAMP WITH TIME ZONE, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pParentid     ALIAS FOR $1;
index cf75249..ebad11c 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION deleteOpportunity(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pOpheadid ALIAS FOR $1;
index f7fd4f2..7b08750 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deletePackage(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   ppkgheadid    ALIAS FOR $1;
index 5c9dbc4..66f012c 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deletePo(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPoheadid ALIAS FOR $1;
index 1c72afe..2a9e662 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION deletepoitem(integer) RETURNS integer AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPoitemid ALIAS FOR $1;
index b19bbeb..bc407b6 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deletePr(CHAR, INTEGER) RETURNS BOOL AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pParentType ALIAS FOR $1;
@@ -19,7 +19,7 @@ END;
 
 
 CREATE OR REPLACE FUNCTION deletePr(INTEGER) RETURNS BOOL AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPrid ALIAS FOR $1;
index bd5b889..9f8e3d3 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteProductCategory(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pProdcatid ALIAS FOR $1;
index f4c4edd..b299a31 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteProfitCenter(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pid ALIAS FOR $1;
index 34a198d..e614c42 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION deleteProject(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPrjid ALIAS FOR $1;
index 336b5ec..d875e00 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION deleteProjectTask(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPrjtaskid ALIAS FOR $1;
index 577d33e..df9f3ab 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteQryhead(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pqryheadid    ALIAS FOR $1;
index ab4972a..4aded6d 100644 (file)
@@ -1,8 +1,8 @@
-SELECT dropIfExists('FUNCTION', 'deleteQuote(integer)', 'public');
-SELECT dropIfExists('FUNCTION', 'deleteQuote(integer, integer)', 'public');
+--SELECT dropIfExists('FUNCTION', 'deleteQuote(integer)', 'public');
+--SELECT dropIfExists('FUNCTION', 'deleteQuote(integer, integer)', 'public');
 
 CREATE OR REPLACE FUNCTION deleteQuote(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pQuheadid ALIAS FOR $1;
@@ -12,7 +12,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION deleteQuote(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pQuheadid ALIAS FOR $1;
@@ -23,7 +23,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION deleteQuote(INTEGER, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pQuheadid    ALIAS FOR $1;
@@ -46,9 +46,14 @@ BEGIN
     _quoteNumber := pQuoteNumber;
   END IF;
 
-  DELETE FROM quitem
+  PERFORM deleteQuoteItem(quitem_id)
+  FROM quitem
   WHERE (quitem_quhead_id=pQuheadid);
 
+  DELETE FROM charass
+  WHERE (charass_target_type='QU')
+    AND (charass_target_id=pQuheadid);
+
   DELETE FROM quhead
   WHERE (quhead_id=pQuheadid);
 
diff --git a/foundation-database/public/functions/deletequoteitem.sql b/foundation-database/public/functions/deletequoteitem.sql
new file mode 100644 (file)
index 0000000..3f2fbdf
--- /dev/null
@@ -0,0 +1,21 @@
+SELECT dropIfExists('FUNCTION', 'deleteQuoteItem(integer)', 'public');
+
+CREATE OR REPLACE FUNCTION deleteQuoteItem(INTEGER) RETURNS INTEGER AS $$
+DECLARE
+  pQuitemid ALIAS FOR $1;
+
+  _result               INTEGER;
+
+BEGIN
+
+  DELETE FROM charass
+  WHERE (charass_target_type='QI')
+    AND (charass_target_id=pQuitemid);
+
+  DELETE FROM quitem
+  WHERE (quitem_id=pQuitemid);
+
+  RETURN 0;
+
+END;
+$$ LANGUAGE 'plpgsql';
index a16a0c6..2770e38 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteRecvForOrder(TEXT, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pordertype   ALIAS FOR $1;
index 592b87d..040f65b 100644 (file)
@@ -1,6 +1,6 @@
 CREATE OR REPLACE FUNCTION deleteSalesCategory(integer) RETURNS integer
     AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSalescatid ALIAS FOR $1;
index cc48b51..b3631c5 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION deleteShippingCharge(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pShipchrgid ALIAS FOR $1;
index d3f1904..08b31af 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteShippingChargeType (integer) RETURNS integer AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pShipchrgid ALIAS FOR $1;
index ac2aeaf..2c86aaf 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION deleteShipto(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pShiptoid ALIAS FOR $1;
index e60f0d5..8efe3d3 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION deleteSo(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSoheadid    ALIAS FOR $1;
@@ -10,7 +10,7 @@ END;
 $$ LANGUAGE plpgsql;
 
 CREATE OR REPLACE FUNCTION deleteSo(INTEGER, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSoheadid    ALIAS FOR $1;
@@ -68,6 +68,10 @@ BEGIN
   DELETE FROM pack
   WHERE (pack_head_id=pSoheadid and pack_head_type = 'SO');
 
+  DELETE FROM charass
+  WHERE (charass_target_type='SO')
+    AND (charass_target_id=pSoheadid);
+
   DELETE FROM cohead
   WHERE (cohead_id=pSoheadid);
 
@@ -79,10 +83,12 @@ BEGIN
   WHERE ((aropenalloc_doctype='S')
     AND  (aropenalloc_doc_id=pSoheadid));
 
-  IF (COALESCE(pSonumber,'') != '') THEN
-    _result = releaseSoNumber(pSonumber);
-  ELSEIF (_r.cohead_number IS NOT NULL) THEN
-    _result = releaseSoNumber(_r.cohead_number);
+  IF ( (NOT _r.cohead_wasquote) AND (NOT _r.cohead_imported) ) THEN
+    IF (COALESCE(pSonumber,'') != '') THEN
+      _result = releaseSoNumber(pSonumber);
+    ELSEIF (_r.cohead_number IS NOT NULL) THEN
+      _result = releaseSoNumber(_r.cohead_number);
+    END IF;
   END IF;
 
   IF (_poStatus < 0) THEN
index c22e910..bd4c4fe 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION deleteSoItem(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSoitemid    ALIAS FOR $1;
@@ -115,6 +115,18 @@ BEGIN
     END IF;
   END IF;
 
+-- Delete characteristic assignments
+  DELETE FROM charass
+  WHERE (charass_target_type='SI')
+    AND (charass_target_id=pSoitemid);
+
+-- Delete reservations
+  IF (fetchMetricBool('EnableSOReservationsByLocation')) THEN
+    DELETE FROM reserve
+    WHERE (reserve_demand_type='SO')
+      AND (reserve_demand_id=pSoitemid);
+  END IF;
+
 -- Delete the coitem
   DELETE FROM coitem
   WHERE (coitem_id=pSoitemid);
index 3dffb34..c937a5c 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION deleteStandardJournal(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pStdjrnlid ALIAS FOR $1;
index 527b729..c9da6f3 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION deleteStandardJournalGroup(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pStdjrnlgrpid ALIAS FOR $1;
index d22c9ca..5bb6b3a 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteSubaccount(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pid ALIAS FOR $1;
index 48da5f3..4f1402f 100644 (file)
@@ -1,7 +1,7 @@
 
 CREATE OR REPLACE FUNCTION deleteSubAccountType (integer) RETURNS integer
     AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSubAccntTypeid ALIAS FOR $1;
index 31be618..d8b6f3d 100644 (file)
@@ -1,7 +1,7 @@
 CREATE OR REPLACE FUNCTION public.deletetax(integer)
   RETURNS integer AS
 $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   ptaxid       ALIAS FOR $1;
index 8af284e..bf58f63 100644 (file)
@@ -1,7 +1,7 @@
 CREATE OR REPLACE FUNCTION deletetaxclass(integer)
   RETURNS integer AS
 $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
 pTaxclassid ALIAS FOR $1;
index 4e22243..d812218 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteTaxType(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTaxtypeid ALIAS FOR $1;
index 41c3145..48b16c3 100644 (file)
@@ -1,7 +1,7 @@
 CREATE OR REPLACE FUNCTION deletetaxzone(integer)
   RETURNS integer AS
 $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
 pTaxzoneid ALIAS FOR $1;
index a790e25..c5954c1 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION deleteTodoItem(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   ptodoItemId ALIAS FOR $1;
index f3d2590..5a5076d 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteUnusedClassCodes() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
 
index 3e695cd..2384b72 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteUnusedFreightClasses() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
 
index 395779b..b5dcf25 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteUnusedProductCategories() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
 
index 28d8b55..f1953c7 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteUOM(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pUomid ALIAS FOR $1;
index 3f658ca..5ceb8b6 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteUOMConv(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pUomconvid ALIAS FOR $1;
index bcdcf14..9296abf 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteUserPreference(TEXT) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPrefname ALIAS FOR $1;
@@ -15,7 +15,7 @@ END;
 ' LANGUAGE plpgsql;
 
 CREATE OR REPLACE FUNCTION deleteUserPreference(TEXT, TEXT) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pUsername ALIAS FOR $1;
index 94126b0..98b0561 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteVendorAddress(INTEGER) RETURNS INTEGER  AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVendaddrid ALIAS FOR $1;
index b54a3aa..d706257 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteVendorType(INTEGER) RETURNS INTEGER  AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVendtypeid ALIAS FOR $1;
index caf10fb..4ddf2d3 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteWo(INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoid ALIAS FOR $1;
@@ -11,7 +11,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION deleteWo(INTEGER, BOOLEAN, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoid ALIAS FOR $1;
@@ -54,17 +54,12 @@ BEGIN
   END IF;
 
   IF (woStatus = 'R') THEN
-    INSERT INTO evntlog (evntlog_evnttime, evntlog_username, evntlog_evnttype_id,
-                         evntlog_ordtype, evntlog_ord_id, evntlog_warehous_id, evntlog_number)
-    SELECT CURRENT_TIMESTAMP, evntnot_username, evnttype_id,
-           'W', wo_id, itemsite_warehous_id, formatWoNumber(wo_id)
-    FROM evntnot, evnttype, itemsite, item, wo
-    WHERE ( (evntnot_evnttype_id=evnttype_id)
-     AND (evntnot_warehous_id=itemsite_warehous_id)
-     AND (wo_itemsite_id=itemsite_id)
-     AND (itemsite_item_id=item_id)
-     AND (evnttype_name='RWoRequestCancel')
-     AND (wo_id=pWoid) );
+    PERFORM postEvent('RWoRequestCancel', 'W', wo_id,
+                      itemsite_warehous_id, formatWoNumber(wo_id),
+                      NULL, NULL, NULL, NULL)
+    FROM wo JOIN itemsite ON (itemsite_id=wo_itemsite_id)
+            JOIN item ON (item_id=itemsite_item_id)
+    WHERE (wo_id=pWoid);
 
      RETURN 0;
   ELSE
index 9206224..d55451b 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION deleteWoMaterial(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWomatlid ALIAS FOR $1;
index 00d191f..5a1c233 100644 (file)
@@ -1,7 +1,7 @@
 CREATE OR REPLACE FUNCTION detachCCPayFromSO(INTEGER, INTEGER, INTEGER)
   RETURNS INTEGER AS
 '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pcoheadid            ALIAS FOR $1;
index e79fdba..8cd2ec0 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION detachContact(INTEGER, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pcntctId    ALIAS FOR $1;
index df497bf..5e42a0f 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION detag(TEXT) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSource ALIAS FOR $1;
index a0b60a1..0eafa94 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION detailedNNQOH(INTEGER, BOOLEAN) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index 4fda36f..aea3e77 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION detailedQOH(INTEGER, BOOLEAN) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index b271356..fac9d6f 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION determineDiscountDate(INTEGER, DATE) RETURNS DATE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTermsid ALIAS FOR $1;
index 51d607a..789fc55 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION determineDueDate(INTEGER, DATE) RETURNS DATE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTermsid ALIAS FOR $1;
index d9793e7..77e7ed5 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION disablePackage(TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   ppkgname ALIAS FOR $1;
@@ -23,7 +23,7 @@ $$
 LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION disablePackage(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   ppkgheadid    ALIAS FOR $1;
index 66ab4dd..01ed663 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION distributeItemlocSeries(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemlocSeries   ALIAS FOR $1;
index a68c72c..c775277 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION distributeToDefault(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemlocdistid ALIAS FOR $1;
@@ -12,7 +12,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION distributeToDefault(INTEGER, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemlocdistid ALIAS FOR $1;
index 01aa555..8ce0fa0 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION distributeToDefaultItemLoc(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemlocdistid ALIAS FOR $1;
@@ -12,7 +12,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION distributeToDefaultItemLoc(INTEGER, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemlocdistid ALIAS FOR $1;
index 653dd94..5d3fad9 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION distributeToLocations(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemlocdistid ALIAS FOR $1;
@@ -120,28 +120,30 @@ BEGIN
           SELECT nextval('shipitemlocrsrv_shipitemlocrsrv_id_seq'),
             shipitem_id, itemloc_itemsite_id, itemloc_location_id,
             itemloc_ls_id, itemloc_expiration, itemloc_warrpurc,
-            least(_itemlocdist.qty, itemlocrsrv_qty)
+            least((_itemlocdist.qty * -1.0), reserve_qty)
           FROM shipitem, itemloc
-            JOIN itemlocrsrv ON (itemloc_id=itemlocrsrv_itemloc_id)
+            JOIN reserve ON (itemloc_id=reserve_supply_id AND reserve_supply_type='I')
           WHERE ( (shipitem_invhist_id=_itemlocdist.invhistid)
             AND   (itemloc_id=_itemlocid)
-            AND   (itemlocrsrv_source=_itemlocdist.ordertype)
-            AND   (itemlocrsrv_source_id=_itemlocdist.orderid) );
+            AND   (reserve_demand_type=_itemlocdist.ordertype)
+            AND   (reserve_demand_id=_itemlocdist.orderid) );
         END IF;
 
---  Update the itemloc reservation
-        UPDATE itemlocrsrv
-        SET itemlocrsrv_qty = (itemlocrsrv_qty + _itemlocdist.qty)
-        WHERE ( (itemlocrsrv_itemloc_id=_itemlocid)
-          AND   (itemlocrsrv_source=_itemlocdist.ordertype)
-          AND   (itemlocrsrv_source_id=_itemlocdist.orderid) );
+--  Update the reservation
+        UPDATE reserve
+        SET reserve_qty = (reserve_qty + _itemlocdist.qty)
+        WHERE ( (reserve_supply_id=_itemlocid)
+          AND   (reserve_supply_type='I')
+          AND   (reserve_demand_type=_itemlocdist.ordertype)
+          AND   (reserve_demand_id=_itemlocdist.orderid) );
           
 --  Delete reservation if fully distributed
-        DELETE FROM itemlocrsrv
-        WHERE ( (itemlocrsrv_itemloc_id=_itemlocid)
-          AND   (itemlocrsrv_source=_itemlocdist.ordertype)
-          AND   (itemlocrsrv_source_id=_itemlocdist.orderid)
-          AND   (itemlocrsrv_qty=0) );
+        DELETE FROM reserve
+        WHERE ( (reserve_supply_id=_itemlocid)
+          AND   (reserve_supply_type='I')
+          AND   (reserve_demand_type=_itemlocdist.ordertype)
+          AND   (reserve_demand_id=_itemlocdist.orderid)
+          AND   (reserve_qty=0) );
       END IF;
     END IF;
 
index 03bcbe4..29fdce4 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION distributeVoucherLine(INTEGER, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVoucherId ALIAS FOR $1;
index 3c8e9cf..3265d99 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION doPostCosts(BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
 
@@ -37,7 +37,7 @@ END;
  ' LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION doPostCosts(INTEGER, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
 
index 83f606b..2e95c8c 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION doUpdateCosts(BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
 
@@ -21,7 +21,7 @@ END;
 ' LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION doUpdateCosts(BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
 
@@ -58,7 +58,7 @@ END;
  ' LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION doUpdateCosts(INTEGER, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
 
@@ -84,7 +84,7 @@ END;
 
 
 CREATE OR REPLACE FUNCTION doUpdateCosts(INTEGER, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
 
index 664ce7e..e8d91c1 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION dropIfExists(TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN dropIfExists($1, $2, 'public');
@@ -7,7 +7,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION dropIfExists(TEXT, TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN dropIfExists($1, $2, $3, false);
@@ -15,7 +15,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION dropIfExists(TEXT, TEXT, TEXT, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pType         ALIAS FOR $1;
@@ -154,7 +154,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION dropIfExists(TEXT, TEXT, TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pType         ALIAS FOR $1;
index 76467c9..8d602aa 100644 (file)
@@ -1,7 +1,7 @@
 CREATE OR REPLACE FUNCTION editccnumber(text, text)
   RETURNS text AS
 '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCcardnum ALIAS FOR $1;
index 1f655c3..19a5939 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION enablePackage(TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   ppkgname  ALIAS FOR $1;
@@ -23,7 +23,7 @@ $$
 LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION enablePackage(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   ppkgheadid    ALIAS FOR $1;
index ece4047..212db31 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION endoftime() RETURNS DATE IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 SELECT DATE('2100-01-01') as result;
 $$ LANGUAGE sql;
index f0e86fc..ad3c766 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION enterCount(int, numeric, text) RETURNS integer AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pInvcntid ALIAS FOR $1;
index 2a8c3a2..d90bbe4 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION enterPoReceipt(INTEGER, NUMERIC) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN enterReceipt(''PO'', $1, $2, 0.0, '''', NULL, NULL);
@@ -8,7 +8,7 @@ END;
 
 
 CREATE OR REPLACE FUNCTION enterPoReceipt(INTEGER, NUMERIC, TEXT) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN enterPoReceipt(''PO'', $1, $2, 0.0, $3, NULL, NULL);
@@ -16,7 +16,7 @@ END;
 ' LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION enterPoReceipt(INTEGER, NUMERIC, NUMERIC, TEXT) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN enterPoReceipt(''PO'', $1, $2, $3, $4, NULL, NULL);
@@ -24,7 +24,7 @@ END;
 ' LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION enterPoReceipt(INTEGER, NUMERIC, NUMERIC, TEXT, INTEGER, DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN enterReceipt(''PO'', $1, $2, $3, $4, $5, $6);
index 5eec0b1..4068188 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION enterPoReturn(INTEGER, NUMERIC, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN enterPoReturn($1, $2, $3, NULL);
@@ -7,7 +7,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION enterPoReturn(INTEGER, NUMERIC, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPoitemid ALIAS FOR $1;
index 2ff1414..520242c 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION enterReceipt(TEXT, INTEGER, NUMERIC, NUMERIC, TEXT, INTEGER, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN enterReceipt($1, $2, $3, $4, $5, $6, $7, NULL);
@@ -7,7 +7,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION enterReceipt(TEXT, INTEGER, NUMERIC, NUMERIC, TEXT, INTEGER, DATE, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pordertype   ALIAS FOR $1;
index d3a6235..bb9b1b0 100644 (file)
@@ -1,7 +1,7 @@
 CREATE OR REPLACE FUNCTION expireCreditCard(integer, bytea)
   RETURNS text AS
 '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCust ALIAS FOR $1;
index 7447656..2faee6d 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION explodeBOM(INTEGER, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
@@ -17,7 +17,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION explodeBOM(INTEGER, INTEGER, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index fbeb3fc..da84dd2 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION explodeKit(INTEGER, INTEGER, INTEGER, INTEGER, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSoheadid ALIAS FOR $1;
@@ -14,7 +14,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION explodeKit(INTEGER, INTEGER, INTEGER, INTEGER, NUMERIC, DATE, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSoheadid ALIAS FOR $1;
@@ -30,7 +30,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION explodeKit(INTEGER, INTEGER, INTEGER, INTEGER, NUMERIC, DATE, DATE, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSoheadid ALIAS FOR $1;
index bc4ec52..f161713 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION explodePhantomOrder(INTEGER, INTEGER, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPlanordid ALIAS FOR $1;
index b36c020..8ed35fd 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION explodeWo(INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoid ALIAS FOR $1;
@@ -84,48 +84,61 @@ BEGIN
 --  Create the W/O Material Requirements
   INSERT INTO womatl
   ( womatl_wo_id, womatl_bomitem_id, womatl_wooper_id, womatl_schedatwooper,
-    womatl_itemsite_id,
-    womatl_duedate,
+    womatl_itemsite_id, womatl_duedate,
     womatl_uom_id, womatl_qtyfxd, womatl_qtyper, womatl_scrap,
     womatl_qtyreq,
     womatl_qtyiss, womatl_qtywipscrap,
     womatl_lastissue, womatl_lastreturn, womatl_cost,
     womatl_picklist, womatl_createwo, womatl_issuewo,
-    womatl_issuemethod, womatl_notes, womatl_ref )
+    womatl_issuemethod, womatl_notes, womatl_ref,
+    womatl_price )
   SELECT wo_id, bomitem_id, bomitem_booitem_seq_id, bomitem_schedatwooper,
-         cs.itemsite_id,
-         CASE WHEN bomitem_schedatwooper THEN COALESCE(calcWooperStartStub(wo_id,bomitem_booitem_seq_id), wo_startdate)
-              ELSE wo_startdate
-         END,
+         matl_itemsite, duedate,
          bomitem_uom_id, bomitem_qtyfxd, bomitem_qtyper, bomitem_scrap,
-         roundQty(itemuomfractionalbyuom(bomitem_item_id, bomitem_uom_id), (bomitem_qtyfxd + bomitem_qtyper * wo_qtyord) * (1 + bomitem_scrap)),
-         0, 0,
+         qtyreq, 0, 0,
          startOfTime(), startOfTime(), 0,
-         item_picklist, ( (item_type='M') AND (bomitem_createwo) ),
-         CASE WHEN ( (item_type='M') AND (bomitem_issuewo) ) THEN TRUE
-              WHEN (cs.itemsite_costmethod='J') THEN TRUE
-              ELSE FALSE
-         END,
-         bomitem_issuemethod, bomitem_notes, bomitem_ref 
-  FROM bomitem, wo, itemsite AS ps, itemsite AS cs, item
-  WHERE ( (wo_itemsite_id=ps.itemsite_id)
-   AND (bomitem_parent_item_id=ps.itemsite_item_id)
-   AND (bomitem_item_id=cs.itemsite_item_id)
-   AND (bomitem_rev_id=wo_bom_rev_id)
-   AND (ps.itemsite_warehous_id=cs.itemsite_warehous_id)
-   AND (cs.itemsite_item_id=item_id)
-   AND (woEffectiveDate(wo_startdate) BETWEEN bomitem_effective AND (bomitem_expires - 1))
-   AND (wo_id=pWoid)
-       AND ((bomitem_char_id IS NULL)
-       OR  EXISTS (
-         SELECT charass_id
-         FROM coitem,charass
-         WHERE ((charass_target_type='SI')
-          AND  (charass_target_id=coitem_id)
-          AND  (charass_char_id=bomitem_char_id)
-          AND  (charass_value=bomitem_value)
-          AND  (wo_ordtype='S')
-          AND  (coitem_id=wo_ordid)))) );
+         item_picklist, ( (item_type='M') AND (bomitem_createwo) ), issuewo,
+         bomitem_issuemethod, bomitem_notes, bomitem_ref,
+         CASE WHEN (price=-9999.0) THEN 0.0
+              ELSE price
+         END
+  FROM (SELECT *, cs.itemsite_id AS matl_itemsite,
+               CASE WHEN bomitem_schedatwooper THEN COALESCE(calcWooperStartStub(wo_id,bomitem_booitem_seq_id), wo_startdate)
+                    ELSE wo_startdate
+               END AS duedate,
+               roundQty(itemuomfractionalbyuom(bomitem_item_id, bomitem_uom_id), (bomitem_qtyfxd + bomitem_qtyper * wo_qtyord) * (1 + bomitem_scrap)) AS qtyreq,
+               CASE WHEN ( (item_type='M') AND (bomitem_issuewo) ) THEN TRUE
+                    WHEN (cs.itemsite_costmethod='J') THEN TRUE
+                    ELSE FALSE
+               END AS issuewo,
+               CASE WHEN (cohead_id IS NULL) THEN item_listprice
+                    ELSE (SELECT itemprice_price
+                          FROM itemIpsPrice(item_id, cohead_cust_id, cohead_shipto_id, 
+                                      roundQty(itemuomfractionalbyuom(bomitem_item_id, bomitem_uom_id), (bomitem_qtyfxd + bomitem_qtyper * wo_qtyord) * (1 + bomitem_scrap)),
+                                      bomitem_uom_id, bomitem_uom_id, cohead_curr_id, CURRENT_DATE, CURRENT_DATE, cohead_warehous_id) LIMIT 1)
+               END AS price
+        FROM wo JOIN itemsite ps ON (ps.itemsite_id=wo_itemsite_id)
+                JOIN bomitem ON (bomitem_parent_item_id=ps.itemsite_item_id AND
+                                 bomitem_rev_id=wo_bom_rev_id AND
+                                 woEffectiveDate(wo_startdate) BETWEEN bomitem_effective and (bomitem_expires - 1))
+                JOIN itemsite cs ON (cs.itemsite_item_id=bomitem_item_id AND
+                                     cs.itemsite_warehous_id=ps.itemsite_warehous_id)
+                JOIN item ON (item_id=cs.itemsite_item_id)
+                LEFT OUTER JOIN coitem ON (wo_ordtype='S' AND
+                                           wo_ordid=coitem_id)
+                LEFT OUTER JOIN cohead ON (cohead_id=coitem_cohead_id)
+        WHERE ( (wo_id=pWoid)
+          AND   ((bomitem_char_id IS NULL)
+             OR  EXISTS (
+                 SELECT charass_id
+                 FROM coitem,charass
+                 WHERE ((charass_target_type='SI')
+                   AND  (charass_target_id=coitem_id)
+                   AND  (charass_char_id=bomitem_char_id)
+                   AND  (charass_value=bomitem_value)
+                   AND  (wo_ordtype='S')
+                   AND  (coitem_id=wo_ordid)))) )
+        ) AS data;
 
 --  Update any created P/R's the have the project id as the parent WO.
   UPDATE pr SET pr_prj_id=wo_prj_id
@@ -173,7 +186,7 @@ BEGIN
       wooper_suconsumed, wooper_sucomplete,
       wooper_rnconsumed, wooper_rncomplete,
       wooper_qtyrcv, wooper_instruc, wooper_scheduled,
-      wooper_wip_location_id )
+      wooper_wip_location_id, wooper_price )
     SELECT wo_id, booitem_id, booitem_seqnumber,
            booitem_wrkcnt_id, booitem_stdopn_id,
            booitem_descrip1, booitem_descrip2, booitem_toolref,
@@ -196,7 +209,8 @@ BEGIN
            0::NUMERIC, FALSE,
            0::NUMERIC, booitem_instruc,
            calculatenextworkingdate(itemsite_warehous_id,wo_startdate,booitem_execday-1),
-           booitem_wip_location_id
+           booitem_wip_location_id,
+           (xtmfg.directlaborcostoper(booitem_id) + xtmfg.overheadcostoper(booitem_id) + xtmfg.machineoverheadcostoper(booitem_id))
     FROM xtmfg.booitem, wo, itemsite
     WHERE ((wo_itemsite_id=itemsite_id)
      AND (itemsite_item_id=booitem_item_id)
index 9690f42..7b51e9e 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION explodeWoEffective() RETURNS TEXT AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _value TEXT;
index bc536d4..fda54b6 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION fetchAPMemoNumber() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT fetchNextNumber('APMemoNumber')::INTEGER;
 $$ LANGUAGE 'sql';
index 1842582..e9b5049 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION fetchARMemoNumber() RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT fetchNextNumber('ARMemoNumber');
 $$ LANGUAGE 'sql';
index d775702..64b6e64 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION fetchCashRcptNumber() RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT fetchNextNumber('CashRcptNumber');
 $$ LANGUAGE 'sql';
index 1bd54f3..f9b6f9c 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION fetchCMNumber() RETURNS text AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT fetchNextNumber('CmNumber');
 $$ LANGUAGE sql;
index ba8395f..b57e152 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION fetchCRMAccountNumber() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT fetchNextNumber('CRMAccountNumber')::INTEGER;
 $$ LANGUAGE 'sql';
index f385d48..3ae9962 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION FetchDefaultFob(pWarehousId INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT warehous_fob
     FROM whsinfo
index 4875fa8..78a5053 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION FetchDefaultShipVia() RETURNS TEXT AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _returnVal TEXT;
index c2d9c9b..a3f7755 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION fetchGLSequence() RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _sequence INTEGER;
index c7e7a23..a4c1ea0 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION fetchIncidentNumber() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT fetchNextNumber('IncidentNumber')::integer;
 $$ LANGUAGE 'sql';
index 233d6bd..523abc6 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION fetchInvcNumber() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT fetchNextNumber('InvcNumber')::integer;
 $$ LANGUAGE 'sql';
index 473577b..858af63 100644 (file)
@@ -1,6 +1,6 @@
 CREATE OR REPLACE FUNCTION fetchItemUomConvTypes(integer)
   RETURNS text[] AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemUomConvId ALIAS FOR $1;
index 1474419..2b0b972 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION fetchjournalnumber(TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pUse ALIAS FOR $1;
index 8483b97..7efa193 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION FetchMetricBool(text) RETURNS BOOLEAN STABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _pMetricName ALIAS FOR $1;
index eb21619..deecb90 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION FetchMetricText(text) RETURNS TEXT STABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _pMetricName ALIAS FOR $1;
index f6ad67f..181fca9 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION FetchMetricValue(text) RETURNS NUMERIC STABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _pMetricName ALIAS FOR $1;
index 5ce14b9..888b310 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION fetchNextCheckNumber(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pBankaccntid ALIAS FOR $1;
index c20b5b9..ed6c5e4 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION fetchNextNumber(TEXT) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   psequence    ALIAS FOR $1;
@@ -56,10 +56,15 @@ BEGIN
   END LOOP;
 
   UPDATE orderseq SET 
-    orderseq_number = _nextnum,
-    orderseq_seqiss = orderseq_seqiss || _seqiss
+    orderseq_number = _nextnum
   WHERE (orderseq_name=psequence);
 
+  IF (fetchMetricBool('EnableGaplessNumbering')) THEN
+    UPDATE orderseq SET 
+      orderseq_seqiss = orderseq_seqiss || _seqiss
+    WHERE (orderseq_name=psequence);
+  END IF;
+
   RETURN _number;
 
 END;
index 764a43b..152635f 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION fetchPoNumber() RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT fetchNextNumber('PoNumber');
 $$ LANGUAGE 'sql';
index ac86024..eb352d1 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION FetchPrefWarehousId() RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _result INTEGER;
index 87dcd26..9db5c9b 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION fetchPrNumber() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT fetchNextNumber('PrNumber')::INTEGER;
 $$ LANGUAGE 'sql';
index e9442be..942ec2a 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION fetchQuNumber() RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT fetchNextNumber('QuNumber');
 $$ LANGUAGE 'sql';
index f430d11..37092b4 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION fetchshipmentnumber() RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _number              TEXT;
index 7ad66fa..26c4d5c 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION fetchSoNumber() RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT fetchNextNumber('SoNumber');
 $$ LANGUAGE 'sql';
index f9b2712..0217ac7 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION fetchToNumber() RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT fetchNextNumber('ToNumber');
 $$ LANGUAGE 'sql';
index 92810ac..fd18c48 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION FetchUsrPrefBool(text) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _pPrefName ALIAS FOR $1;
index a6914a2..1bc50b1 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION fetchVoNumber() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT fetchNextNumber('VcNumber')::INTEGER;
 $$ LANGUAGE 'sql';
index 4c485d4..9a7c3e7 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION fetchWoNumber() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT fetchNextNumber('WoNumber')::INTEGER;
 $$ LANGUAGE 'sql';
index 98f2569..84b2a52 100644 (file)
@@ -4,7 +4,7 @@ SELECT dropIfExists('FUNCTION','financialreport(INTEGER, INTEGER, bool, bool)');
 SELECT dropIfExists('FUNCTION','financialreport(INTEGER,_int4,bpchar,bool)');
 
 CREATE OR REPLACE FUNCTION financialreport(INTEGER, INTEGER, INTEGER) RETURNS bool AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pFlheadid ALIAS FOR $1;
@@ -22,7 +22,7 @@ $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION financialreport(INTEGER, INTEGER, bpchar, INTEGER)
   RETURNS bool AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pFlheadid ALIAS FOR $1;
@@ -241,7 +241,7 @@ $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION financialreport(INTEGER, INTEGER, bool, bool, INTEGER)
   RETURNS SETOF flstmtitem AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pFlcolid ALIAS FOR $1;
@@ -1263,7 +1263,7 @@ $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION financialreport(INTEGER,_int4,bpchar,bool,INTEGER)
   RETURNS SETOF fltrenditem AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pFlheadId ALIAS FOR $1;
index 456cb73..e2a001e 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION findAPAccount(INTEGER) RETURNS INTEGER STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVendid ALIAS FOR $1;
index c5320a2..0e5fb28 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION findAPDiscountAccount(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVendid ALIAS FOR $1;
index 12ee6d8..a3dc364 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION findAPPrepaidAccount(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVendid ALIAS FOR $1;
index a2ae24c..ee1db18 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION findARAccount(INTEGER) RETURNS INTEGER STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCustid ALIAS FOR $1;
index 8b788c0..919ca2a 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION findardiscountaccount(integer) RETURNS integer AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCustid ALIAS FOR $1;
index 21314aa..7e6278d 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION findCalendarOrigin(INTEGER) RETURNS DATE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCalheadid ALIAS FOR $1;
index 0c0b3e9..55ad5ac 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION findCustomerForm(INTEGER, CHARACTER(1)) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCustid ALIAS FOR $1;
index d0baf89..1c69267 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION findDeferredAccount(INTEGER) RETURNS INTEGER STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCustid ALIAS FOR $1;
index 24e9e7c..0bc54ee 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION findFreightAccount(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCustid ALIAS FOR $1;
index fce5fe5..97d48a2 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION findPeriodEnd(INTEGER) RETURNS DATE STABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCalitemid ALIAS FOR $1;
index 7b592b4..8ba76ca 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION findPeriodStart(INTEGER) RETURNS DATE STABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCalitemid ALIAS FOR $1;
index 26033ee..c18ec09 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION findPrepaidAccount(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCustid ALIAS FOR $1;
index 65a37a4..fdab19d 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION findSalesAccnt(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN findSalesAccnt($1, 'IS', $2, NULL, NULL);
@@ -7,7 +7,7 @@ END;
 $$ LANGUAGE plpgsql;
 
 CREATE OR REPLACE FUNCTION findSalesAccnt(INTEGER, TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN findSalesAccnt($1, $2, $3, NULL, NULL);
@@ -19,7 +19,7 @@ CREATE OR REPLACE FUNCTION findSalesAccnt(pid INTEGER,
                                           pCustid INTEGER,
                                           pSaletypeid INTEGER,
                                           pShipzoneid INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _s RECORD;
index 7ad797d..afe2149 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION findSpecialFinancial(TEXT, TEXT, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pUnit ALIAS FOR $1;
@@ -44,7 +44,7 @@ END;
 ' LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION copyFinancialLayout(INTEGER, TEXT) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSourceFlheadid ALIAS FOR $1;
index 268b3fe..3fb9111 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION firstLine(TEXT) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSource ALIAS FOR $1;
index 4b10459..38ef493 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION fixACL() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _r        RECORD;
index fc9f930..eae227b 100644 (file)
@@ -3,7 +3,7 @@
 CREATE OR REPLACE FUNCTION formatabachecks(integer, integer, text)
   RETURNS SETOF achline AS
 $BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pbankaccntid     ALIAS FOR $1;   -- all unprinted checks for this bankaccnt
index 672ec46..98d4600 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION formatACHChecks(INTEGER, INTEGER, TEXT) RETURNS SETOF achline AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pbankaccntid     ALIAS FOR $1;   -- all unprinted checks for this bankaccnt
index b88ee9f..f8ca308 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION formatACHCompanyId() RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN CASE WHEN fetchMetricText('ACHCompanyIdType') = 'D' THEN '3'
index 1ae19a2..1c9cea4 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION formatAddr(INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pAddrId       ALIAS FOR $1;
@@ -19,7 +19,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION formatAddr(TEXT, TEXT, TEXT, TEXT, INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   f_addr1 ALIAS FOR $1;
@@ -34,7 +34,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION formatAddr(TEXT, TEXT, TEXT, TEXT, TEXT, INTEGER) RETURNS TEXT AS $$ 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   f_addr1 ALIAS FOR $1;
@@ -94,7 +94,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION formatAddr(TEXT, TEXT, TEXT, TEXT, TEXT) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   f_addr1 ALIAS FOR $1;
index 58d8977..3bdb039 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION formatBoolYN(BOOLEAN) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE pBool ALIAS FOR $1;
 BEGIN
index 4c84694..b0dd6bf 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION formatBooSeq(INTEGER, INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index 161915f..a62ce8b 100644 (file)
@@ -1,7 +1,7 @@
 CREATE OR REPLACE FUNCTION formatbytea(bytea)
   RETURNS text AS
 '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pField ALIAS FOR $1;
index aa4ec79..ad43a34 100644 (file)
@@ -1,7 +1,7 @@
 CREATE OR REPLACE FUNCTION formatCCdashes(text, text)
   RETURNS text AS
 '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCCard ALIAS FOR $1;
index 8b817c4..df04e2a 100644 (file)
@@ -1,7 +1,7 @@
 CREATE OR REPLACE FUNCTION formatccnumber(text)
   RETURNS text AS
 '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCcardnum ALIAS FOR $1;
@@ -38,7 +38,7 @@ END;
 CREATE OR REPLACE FUNCTION formatccnumber(bytea)
   RETURNS text AS
 '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCcardnum ALIAS FOR $1;
index c8aa61d..73b3979 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION formatCntctName(INTEGER) RETURNS TEXT AS $$ 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCntctId ALIAS FOR $1;
@@ -24,7 +24,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION formatCntctName(TEXT, TEXT, TEXT, TEXT, TEXT) RETURNS TEXT AS $$ 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pHonorific ALIAS FOR $1;
index 4f8072a..f8844b3 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION formatCost(NUMERIC) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN formatNumeric($1, ''cost'');
index dd0fb3f..a8fe385 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION formatCountTagBarcode(INTEGER) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCnttagid ALIAS FOR $1;
index 22a8ba3..7e61855 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION formatCreditMemoNumber(INTEGER) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCmheadid ALIAS FOR $1;
index 53c263d..ce7a9a7 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION formatDate(TIMESTAMP WITH TIME ZONE) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 SELECT TO_CHAR($1, COALESCE((SELECT locale_dateformat
                              FROM locale, usr
@@ -11,7 +11,7 @@ SELECT TO_CHAR($1, COALESCE((SELECT locale_dateformat
 
 
 CREATE OR REPLACE FUNCTION formatDate(DATE) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 SELECT TO_CHAR($1, COALESCE((SELECT locale_dateformat
                              FROM locale, usr
@@ -21,7 +21,7 @@ SELECT TO_CHAR($1, COALESCE((SELECT locale_dateformat
 ' LANGUAGE 'sql';
 
 CREATE OR REPLACE FUNCTION formatDate(DATE, TEXT) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pDate ALIAS FOR $1;
index 45c590f..dd8a523 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION formatDateTime(TIMESTAMP WITHOUT TIME ZONE) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 SELECT TO_CHAR($1, COALESCE((SELECT locale_timestampformat
                              FROM locale, usr
@@ -10,7 +10,7 @@ SELECT TO_CHAR($1, COALESCE((SELECT locale_timestampformat
 ' LANGUAGE 'sql';
 
 CREATE OR REPLACE FUNCTION formatDateTime(TIMESTAMP WITH TIME ZONE) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 SELECT TO_CHAR($1, COALESCE((SELECT locale_timestampformat
                              FROM locale, usr
index 561031d..a6aa8de 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION formatExtPrice(NUMERIC) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN formatNumeric($1, ''extprice'');
index d9f1943..ae8a1ce 100644 (file)
@@ -1,6 +1,6 @@
 CREATE OR REPLACE FUNCTION formatflitemdescrip(int4)
   RETURNS text AS  '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pFlitemId ALIAS FOR $1;
index fc31686..eb3d449 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION formatGLAccount(INTEGER) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pAccntid ALIAS FOR $1;
@@ -25,7 +25,7 @@ END;
 $$      LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION formatGLAccount(TEXT, TEXT, TEXT, TEXT) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCompany ALIAS FOR $1;
index c4121eb..0fa3cc4 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION formatGLAccountLong(INTEGER) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pAccntid ALIAS FOR $1;
index 2fbb9b6..1e015ca 100644 (file)
@@ -1,7 +1,7 @@
 
 CREATE OR REPLACE FUNCTION formatindent(text,int4)
   RETURNS text AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pText ALIAS FOR $1;
index eb76170..cbe1f16 100644 (file)
@@ -1,7 +1,7 @@
 
 -- treat NUMERIC as number of minutes
 CREATE OR REPLACE FUNCTION formatInterval(NUMERIC) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT TO_CHAR((''@ '' || trunc($1) || '' min '' ||
                              ($1 - trunc($1)) * 60 || '' sec'')::INTERVAL,
@@ -12,7 +12,7 @@ CREATE OR REPLACE FUNCTION formatInterval(NUMERIC) RETURNS TEXT IMMUTABLE AS '
 ' LANGUAGE 'sql';
 
 CREATE OR REPLACE FUNCTION formatInterval(INTERVAL) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT TO_CHAR($1, ( SELECT locale_intervalformat
                        FROM locale, usr
index b8665f4..cb8c7fe 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION formatInvcNumber(INTEGER) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCobmiscid ALIAS FOR $1;
index aa4172a..90560d7 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION formatItemSiteBarcode(INTEGER) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index 08caa7b..0d650a9 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION formatLocationBarcode(INTEGER) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pLocationid ALIAS FOR $1;
index 95afeb9..da80e1b 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION formatLocationContentsBarcode(INTEGER) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pLocationid ALIAS FOR $1;
index 402f2b9..e1d87b3 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION formatLocationIssueBarcode(INTEGER) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pLocationid ALIAS FOR $1;
index 66d5ce9..bc0c272 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION formatLocationName(INTEGER) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pLocationid ALIAS FOR $1;
index 4d6cb17..a411a28 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION formatLotSerialNumber(INTEGER) RETURNS TEXT AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pLotSerialId ALIAS FOR $1;
index 2267f6b..f05c4f3 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION formatMoney(NUMERIC) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN formatNumeric($1, ''curr'');
index 2c6a108..8647013 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION formatNumeric(NUMERIC, TEXT) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _value        NUMERIC := $1;
index 4918694..43751d8 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION formatPeriodName( INTEGER,  char) RETURNS text AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPeriodId ALIAS FOR $1;
index 0771a6f..d760768 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION formatPloNumber(INTEGER) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPlanordid ALIAS FOR $1;
index e2d696f..a1c004f 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION formatPrcnt(NUMERIC) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 SELECT formatNumeric($1 * 100, 'percent')  AS result
 $$ LANGUAGE 'sql';
index 114188b..59fdbd0 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION formatPrice(NUMERIC) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT formatNumeric($1, 'salesprice') AS result;
 $$ LANGUAGE 'sql';
index a8bf710..03d46ae 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION formatPurchPrice(NUMERIC) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN formatNumeric($1, ''purchprice'');
index 6763578..a65d90e 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION formatQty(NUMERIC) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN formatNumeric($1, ''qty'');
index 38d1785..6b3801e 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION formatQtyPer(NUMERIC) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN formatNumeric($1, ''qtyper'');
index 1f58055..44b099b 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION formatRatio(NUMERIC) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT formatNumeric($1, 'uomratio');
 $$ LANGUAGE 'sql';
index 0e375d4..f06b097 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION formatRevNumber(TEXT, INTEGER) RETURNS TEXT AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pRevType     ALIAS FOR $1;
index c414592..be32dd9 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION formatSalesPrice(NUMERIC) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN formatNumeric($1, ''salesprice'');
index d271b9b..6bd33c3 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION formatScrap(NUMERIC) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT formatNumeric(($1 * 100), 'percent') AS result
 $$ LANGUAGE 'sql';
index 1661bb9..aec8801 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION formatShipmentNumber(INTEGER) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pshipheadid    ALIAS FOR $1;
index f9ea059..456b1da 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION formatSoBarcode(INTEGER) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSoheadid ALIAS FOR $1;
index b6c378c..dea42f1 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION formatSoitemBarcode(INTEGER) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSoitemid ALIAS FOR $1;
index 92b1ac2..b1b7c1a 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION formatSoitemNumber(INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   targetSoitemid ALIAS FOR $1;
index a4586c6..5d6aca0 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION formatSoLineNumber(INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSoitemid ALIAS FOR $1;
index 1036828..4a1f6e6 100644 (file)
@@ -1,7 +1,7 @@
 CREATE OR REPLACE FUNCTION formatSoNumber(INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 SELECT COALESCE((SELECT (text(cohead_number) || '-' || formatSoLineNumber(coitem_id))
                    FROM coitem JOIN cohead ON (coitem_cohead_id=cohead_id)
                   WHERE (coitem_id=($1))),'DELETED');
-$$ LANGUAGE 'SQL' STABLE;
+$$ LANGUAGE 'sql' STABLE;
index f7c5d4e..f32d1eb 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION formatTime(TIMESTAMP WITH TIME ZONE) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT TO_CHAR($1, ( SELECT locale_timeformat
                        FROM locale, usr
@@ -10,7 +10,7 @@ CREATE OR REPLACE FUNCTION formatTime(TIMESTAMP WITH TIME ZONE) RETURNS TEXT IMM
 
 
 CREATE OR REPLACE FUNCTION formatTime(NUMERIC) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT LTRIM(TO_CHAR(COALESCE($1, 0), ''999999990.0''));
 ' LANGUAGE 'sql';
index 997b944..42d321d 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION formatUOMRatio(NUMERIC) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN formatNumeric($1, ''uomratio'');
index 4a8964f..45d3d65 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION formatUserBarcode(INTEGER) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pUserid ALIAS FOR $1;
@@ -17,7 +17,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION formatUserBarcode(TEXT) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pUsername ALIAS FOR $1;
index a700536..2ef0a49 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION formatWeight(NUMERIC) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 SELECT formatNumeric($1, 'weight') AS result
 $$ LANGUAGE 'sql';
index f936709..807454c 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION formatWoBarcode(INTEGER) RETURNS TEXT IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoid ALIAS FOR $1;
index 92c6234..4780eb1 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION formatWoNumber(integer) RETURNS TEXT IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoid ALIAS FOR $1;
index 0c80ae2..d46cea4 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION formatwooperseq(INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWooperId  ALIAS FOR $1;
index 0c90ec1..ab59250 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION forwardUpdateAccount(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pAccntid ALIAS FOR $1;
index 8b9dff2..15fde35 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION forwardUpdateInvBalance(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pInvbalid ALIAS FOR $1;
index 2ca4d08..d40d5dc 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION forwardUpdateItemsite(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteId ALIAS FOR $1;
index 6f090c3..889d0ae 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION forwardUpdateTrialBalance(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTrialbalid ALIAS FOR $1;
index 5e96012..a691064 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION freezeAccountingPeriod(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPeriodid ALIAS FOR $1;
index c554f8a..b6cb1f6 100644 (file)
@@ -1,7 +1,7 @@
 
 CREATE OR REPLACE FUNCTION freightDetail(text,integer,integer,integer,date,text,integer)
   RETURNS SETOF freightData AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pOrderType ALIAS FOR $1;
index 7bc2346..e483bb3 100644 (file)
@@ -1,7 +1,7 @@
 
 CREATE OR REPLACE FUNCTION freightDetailQuote(integer,text,integer,text,date,text,text,text[][])
   RETURNS SETOF freightData AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCustId ALIAS FOR $1;
index 684de97..6ec5f31 100644 (file)
@@ -1,7 +1,7 @@
 -- if $3 == true then calculate freight on posted records
 -- if $3 == false then calculate freight on unposted records
 CREATE OR REPLACE FUNCTION freightForRecv(TEXT, INTEGER, BOOLEAN) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pordertype   ALIAS FOR $1;
index 57b809a..55a683e 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getActiveRevId(TEXT,INTEGER) RETURNS INTEGER STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTargetType ALIAS FOR $1;
index c632b5b..d16db85 100644 (file)
@@ -1,11 +1,10 @@
-CREATE OR REPLACE FUNCTION getAddrId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION getAddrId(pAddressNumber text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
-  pAddressNumber ALIAS FOR $1;
   _returnVal INTEGER;
 BEGIN
-  IF (pAddressNumber IS NULL OR pAddressNumber = '''') THEN
+  IF (pAddressNumber IS NULL OR pAddressNumber = '') THEN
     RETURN NULL;
   END IF;
 
@@ -14,9 +13,9 @@ BEGIN
   WHERE (addr_number=pAddressNumber);
 
   IF (_returnVal IS NULL) THEN
-       RAISE EXCEPTION ''Address Number % not found.'', pAddressNumber;
+       RAISE EXCEPTION 'Address Number % not found.', pAddressNumber;
   END IF;
 
   RETURN _returnVal;
 END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
index a1799c7..9a346d0 100644 (file)
@@ -1,7 +1,7 @@
 CREATE OR REPLACE FUNCTION getadjustmenttaxtypeid()
   RETURNS integer AS
 $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _taxtypeid INTEGER;
index 66787a4..ce64856 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getAropenId(text, character, text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCustNumber ALIAS FOR $1;
index bd76d94..564ddee 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getBankAccntId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pBankAccntName ALIAS FOR $1;
index 36657d1..dc81462 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getBomitemId(text,text,text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemNumber ALIAS FOR $1;
index ca18cfe..7988cf1 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getBooitemSeqId(text,text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemNumber ALIAS FOR $1;
index eb5aef5..7943768 100755 (executable)
@@ -1,6 +1,6 @@
 CREATE OR REPLACE FUNCTION getBudgheadId(text)
   RETURNS integer AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pBudghead ALIAS FOR $1;
index 105895a..1cda26a 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getCashrcptId(text, text, text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCustNumber ALIAS FOR $1;
index ff0779a..7309bd7 100644 (file)
@@ -1,9 +1,8 @@
-CREATE OR REPLACE FUNCTION getCharId(text, text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION getCharId(pChar text,
+                                     pType text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
-  pChar ALIAS FOR $1;
-  pType ALIAS FOR $2;
   _returnVal INTEGER;
 BEGIN
   IF (COALESCE(pChar, '') = '') THEN
index 62ff3de..d8f7827 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getClassCodeId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pClassCode ALIAS FOR $1;
index c79d086..e91efe7 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getCmheadId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCreditMemoNumber ALIAS FOR $1;
@@ -9,7 +9,7 @@ END;
 ' LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION getCmheadId(text, boolean) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCreditMemoNumber ALIAS FOR $1;
index 4144f8a..b460f39 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getCmntTypeId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCmntType ALIAS FOR $1;
index 5bd113f..675d7bb 100644 (file)
@@ -1,8 +1,7 @@
-CREATE OR REPLACE FUNCTION getCntctId(text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION getCntctId(pContactNumber text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
-  pContactNumber ALIAS FOR $1;
   _returnVal INTEGER;
 BEGIN
   SELECT getCntctId(pContactNumber,true) INTO _returnVal;
@@ -11,12 +10,11 @@ BEGIN
 END;
 $$ LANGUAGE 'plpgsql';
 
-CREATE OR REPLACE FUNCTION getCntctId(text,boolean) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION getCntctId(pContactNumber text,
+                                      pNotFoundErr boolean) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
-  pContactNumber ALIAS FOR $1;
-  pNotFoundErr ALIAS FOR $2;
   _returnVal INTEGER;
 BEGIN
   IF (COALESCE(TRIM(pContactNumber), '') = '') THEN
index f55d42b..e6190de 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getCoheadId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSalesOrderNumber ALIAS FOR $1;
index 8cb8b8c..e57df27 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getCoItemId(text,text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSalesOrderNumber    ALIAS FOR $1;
index d0113f0..b27ffcc 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getContrctEffective(pContrctNumber text) RETURNS DATE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _returnVal DATE;
index a040704..b2c20cc 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getContrctExpires(pContrctNumber text) RETURNS DATE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _returnVal DATE;
index dad1ff9..dcef3b1 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getContrctId(pContrctNumber text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _returnVal INTEGER;
index a40395f..2ebc6e3 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getCostCatId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCostCat ALIAS FOR $1;
index c26f8a6..99d17c1 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getCostElemId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCostElemType ALIAS FOR $1;
index 9831501..5b07a1b 100644 (file)
@@ -1,8 +1,7 @@
-CREATE OR REPLACE FUNCTION getCrmAcctId(text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION getCrmAcctId(pAcctNumber text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
-  pAcctNumber ALIAS FOR $1;
   _returnVal INTEGER;
 BEGIN
   
index ff473da..ad676cc 100644 (file)
@@ -1,8 +1,7 @@
-CREATE OR REPLACE FUNCTION getCurrId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION getCurrId(pCurrName text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
-  pCurrName ALIAS FOR $1;
   _returnVal INTEGER;
 BEGIN
   IF (pCurrName IS NULL) THEN
@@ -14,9 +13,9 @@ BEGIN
   WHERE (curr_abbr=pCurrName);
 
   IF (_returnVal IS NULL) THEN
-       RAISE EXCEPTION ''Currency % not found.'', pCurrName;
+       RAISE EXCEPTION 'Currency % not found.', pCurrName;
   END IF;
 
   RETURN _returnVal;
 END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
index 635c593..02f0469 100644 (file)
@@ -1,8 +1,7 @@
-CREATE OR REPLACE FUNCTION getCustId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION getCustId(pCustNumber text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
-  pCustNumber ALIAS FOR $1;
   _returnVal INTEGER;
 BEGIN
   
@@ -10,14 +9,13 @@ BEGIN
 
   RETURN _returnVal;
 END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
 
-CREATE OR REPLACE FUNCTION getCustId(text,boolean) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION getCustId(pCustNumber text,
+                                     pInclProspects boolean) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
-  pCustNumber ALIAS FOR $1;
-  pInclProspects ALIAS FOR $2;
   _returnVal INTEGER;
 BEGIN
   IF (pCustNumber IS NULL) THEN
@@ -34,13 +32,13 @@ BEGIN
       FROM prospect
       WHERE (UPPER(prospect_number)=UPPER(pCustNumber));
       IF (_returnVal IS NULL) THEN
-        RAISE EXCEPTION ''Neither Customer nor Prospect Number % found.'', pCustNumber;
+        RAISE EXCEPTION 'Neither Customer nor Prospect Number % found.', pCustNumber;
       END IF;
     ELSE
-      RAISE EXCEPTION ''Customer Number % not found.'', pCustNumber;
+      RAISE EXCEPTION 'Customer Number % not found.', pCustNumber;
     END IF;
   END IF;
 
   RETURN _returnVal;
 END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
index 29925b2..a7fb641 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getCustNameFromInfo(TEXT, TEXT, TEXT, TEXT, TEXT, BOOLEAN) RETURNS TEXT AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _email       TEXT    := COALESCE(UPPER($1), '''');
index b47894f..22c9b4c 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getCustTypeId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCustTypeCode ALIAS FOR $1;
index cc646d9..eb0bd3f 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getDeptId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pDeptNumber ALIAS FOR $1;
index aac3d57..a58ed8d 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION getEdiProfileId(text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pEdiProfileName ALIAS FOR $1;
index 59df648..4d20d07 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION getEdiProfileName(INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pEdiProfileId ALIAS FOR $1;
index f8b1ce1..4975190 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getEffectiveXtUser() RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
 /*
index ee13021..c551620 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getEmpId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pEmpCode ALIAS FOR $1;
index 87132fc..75f5219 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getExpcatId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pExpcatCode ALIAS FOR $1;
index fc6cfa8..5483009 100644 (file)
@@ -1,6 +1,6 @@
 CREATE OR REPLACE FUNCTION getflcoldata(int4, int4)
   RETURNS SETOF flcoldata AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pFlcolid ALIAS FOR $1;
@@ -281,7 +281,7 @@ $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION getflcoldata(char(1), int[], boolean)
   RETURNS SETOF flcoldata AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pInterval ALIAS FOR $1;
index 9463920..9b96b93 100644 (file)
@@ -1,6 +1,6 @@
 CREATE OR REPLACE FUNCTION getflstmthead(int4, int4)
   RETURNS SETOF flstmthead AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pFlcolid ALIAS FOR $1;
index a945077..40e35d6 100644 (file)
@@ -1,6 +1,6 @@
 CREATE OR REPLACE FUNCTION getfltrendhead(INTEGER, _int4, bpChar)
   RETURNS SETOF fltrendhead AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pFlheadid ALIAS FOR $1;
index aee14ae..d1c2ae7 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getFreightClassId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pFreightClassCode ALIAS FOR $1;
index 4839e6c..567bd8c 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getFreightTaxTypeId() RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _taxtypeid INTEGER;
index db3068c..d0007e6 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION getGainLossAccntId(integer) RETURNS INTEGER STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pAccntId ALIAS FOR $1;
index 54e37af..ff61eb2 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION getGlAccntId(text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pGlAccnt ALIAS FOR $1;
@@ -23,7 +23,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION getglaccntid(TEXT,TEXT,TEXT,TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCompany ALIAS FOR $1;
index 8124a37..1be5248 100644 (file)
@@ -1,11 +1,10 @@
-CREATE OR REPLACE FUNCTION getImageId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION getImageId(pImageName text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
-  pImageName ALIAS FOR $1;
   _returnVal INTEGER;
 BEGIN
-  IF (COALESCE(TRIM(pImageName), '''') = '''') THEN
+  IF (COALESCE(TRIM(pImageName), '') = '') THEN
     RETURN NULL;
   END IF;
 
@@ -14,9 +13,9 @@ BEGIN
   WHERE (image_name=pImageName);
 
   IF (_returnVal IS NULL) THEN
-    RAISE EXCEPTION ''Image % not found.'', pImageName;
+    RAISE EXCEPTION 'Image % not found.', pImageName;
   END IF;
 
   RETURN _returnVal;
 END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
index 81e3c8c..f7d2492 100644 (file)
@@ -1,9 +1,8 @@
 
-CREATE OR REPLACE FUNCTION getIncdtCatId(text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION getIncdtCatId(pIncdtCatName text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
-  pIncdtCatName ALIAS FOR $1;
   _returnVal INTEGER;
 BEGIN
   IF (pIncdtCatName IS NULL) THEN
index 9a8fb1c..91246a7 100644 (file)
@@ -1,8 +1,7 @@
-CREATE OR REPLACE FUNCTION getIncdtCrmAcctId(integer) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION getIncdtCrmAcctId(pIncidentNumber integer) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
-  pIncidentNumber ALIAS FOR $1;
   _returnVal INTEGER;
 BEGIN
   IF (pIncidentNumber IS NULL) THEN
@@ -14,9 +13,9 @@ BEGIN
   WHERE (incdt_number=pIncidentNumber);
 
   IF (_returnVal IS NULL) THEN
-       RAISE EXCEPTION ''Incident Number % not found.'', pIncidentNumber;
+       RAISE EXCEPTION 'Incident Number % not found.', pIncidentNumber;
   END IF;
 
   RETURN _returnVal;
 END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
index 688b003..cf485d0 100644 (file)
@@ -1,8 +1,7 @@
-CREATE OR REPLACE FUNCTION getIncdtPriorityId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION getIncdtPriorityId(pIncdtPriorityName text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
-  pIncdtPriorityName ALIAS FOR $1;
   _returnVal INTEGER;
 BEGIN
   IF (pIncdtPriorityName IS NULL) THEN
@@ -14,9 +13,9 @@ BEGIN
   WHERE (incdtpriority_name=pIncdtPriorityName);
 
   IF (_returnVal IS NULL) THEN
-       RAISE EXCEPTION ''Incident Priority Name % not found.'', pIncdtPriorityName;
+       RAISE EXCEPTION 'Incident Priority Name % not found.', pIncdtPriorityName;
   END IF;
 
   RETURN _returnVal;
 END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
index 82d45b0..037be20 100644 (file)
@@ -1,8 +1,7 @@
-CREATE OR REPLACE FUNCTION getIncdtResolutionId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION getIncdtResolutionId(pIncdtResolutionName text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
-  pIncdtResolutionName ALIAS FOR $1;
   _returnVal INTEGER;
 BEGIN
   IF (pIncdtResolutionName IS NULL) THEN
@@ -14,9 +13,9 @@ BEGIN
   WHERE (incdtresolution_name=pIncdtResolutionName);
 
   IF (_returnVal IS NULL) THEN
-       RAISE EXCEPTION ''Incident Resolution Name % not found.'', pIncdtResolutionName;
+       RAISE EXCEPTION 'Incident Resolution Name % not found.', pIncdtResolutionName;
   END IF;
 
   RETURN _returnVal;
 END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
index 9c6d985..49378ce 100644 (file)
@@ -1,8 +1,7 @@
-CREATE OR REPLACE FUNCTION getIncdtSeverityId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION getIncdtSeverityId(pIncdtSeverityName text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
-  pIncdtSeverityName ALIAS FOR $1;
   _returnVal INTEGER;
 BEGIN
   IF (pIncdtSeverityName IS NULL) THEN
@@ -14,9 +13,9 @@ BEGIN
   WHERE (incdtseverity_name=pIncdtSeverityName);
 
   IF (_returnVal IS NULL) THEN
-       RAISE EXCEPTION ''Incident Severity Name % not found.'', pIncdtSeverityName;
+       RAISE EXCEPTION 'Incident Severity Name % not found.', pIncdtSeverityName;
   END IF;
 
   RETURN _returnVal;
 END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
index 3e1dd0e..d5f0bd7 100644 (file)
@@ -1,8 +1,7 @@
-CREATE OR REPLACE FUNCTION getIncidentId(integer) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION getIncidentId(pIncidentNumber integer) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
-  pIncidentNumber ALIAS FOR $1;
   _returnVal INTEGER;
 BEGIN
   IF (pIncidentNumber IS NULL) THEN
@@ -14,9 +13,9 @@ BEGIN
   WHERE (incdt_number=pIncidentNumber);
 
   IF (_returnVal IS NULL) THEN
-       RAISE EXCEPTION ''Incident Number % not found.'', pIncidentNumber;
+       RAISE EXCEPTION 'Incident Number % not found.', pIncidentNumber;
   END IF;
 
   RETURN _returnVal;
 END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
index c4adb90..f9aaa50 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getInvcheadId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pInvcNumber ALIAS FOR $1;
index 0d6fc4f..30f4d87 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION getInvcitemLotSerial(INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pInvcitemid ALIAS FOR $1;
index a84d19b..f56a507 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getIpsheadId(pIpsName TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _returnVal INTEGER;
index e3acb6f..72a9a1e 100644 (file)
@@ -3,7 +3,7 @@ CREATE OR REPLACE FUNCTION getIpsitemId(pIpsName TEXT,
                                         pQtyBreak NUMERIC,
                                         pQtyUom TEXT,
                                         pPriceUom TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _returnVal INTEGER;
index 9eaf2f5..8ecb984 100644 (file)
@@ -1,7 +1,7 @@
 CREATE OR REPLACE FUNCTION getIpsProdcatId(pIpsName TEXT,
                                            pProdCat TEXT,
                                            pQtyBreak NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _returnVal INTEGER;
index 4b53903..0e7b46b 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getItemId(text) RETURNS INTEGER IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemNumber ALIAS FOR $1;
index 8cd538a..eea2313 100644 (file)
@@ -2,7 +2,7 @@
 CREATE OR REPLACE FUNCTION getitemidfromupc(text)
   RETURNS integer AS
 $BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemUPC ALIAS FOR $1;
index abd19f7..1662692 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getItemsiteId(text, text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWarehouseCode ALIAS FOR $1;
@@ -13,7 +13,7 @@ END;
 ' LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION getItemsiteId(text, text, text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWarehouseCode ALIAS FOR $1;
index 8d5a5c0..59ee3b5 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getItemSrcId(text,text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemNumber ALIAS FOR $1;
index c31917c..a1233c2 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getItemTaxType(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index a806569..dc1b552 100644 (file)
@@ -1,7 +1,7 @@
 
 CREATE OR REPLACE FUNCTION getlasttrialbalid(INTEGER, INTEGER)
   RETURNS INTEGER STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pAccntId ALIAS FOR $1;
index 2735367..2694ce8 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getLocationId(text,text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWarehouse ALIAS FOR $1;
index f429130..7b6b17f 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getLotSerialId(text, text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemNumber ALIAS FOR $1;
diff --git a/foundation-database/public/functions/getopenshipment.sql b/foundation-database/public/functions/getopenshipment.sql
new file mode 100644 (file)
index 0000000..4ed4376
--- /dev/null
@@ -0,0 +1,77 @@
+CREATE OR REPLACE FUNCTION getOpenShipment(pOrderType TEXT,
+                                           pOrderId INTEGER,
+                                           pWarehousId INTEGER) RETURNS TEXT AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
+-- See www.xtuple.com/CPAL for the full text of the software license.
+DECLARE
+  _result TEXT := '';
+
+BEGIN
+
+  IF (pOrderType = 'SO') THEN
+    SELECT shiphead_number INTO _result
+    FROM shiphead JOIN shipitem ON (shipitem_shiphead_id=shiphead_id)
+                  JOIN coitem ON (coitem_id=shipitem_orderitem_id)
+                  JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
+    WHERE (shiphead_order_id=pOrderId)
+      AND (shiphead_order_type='SO') 
+      AND (NOT shiphead_shipped)
+      AND (CASE WHEN (pWarehousId IS NULL) THEN TRUE
+                ELSE itemsite_warehous_id=pWarehousId END) 
+    ORDER BY shiphead_number
+    LIMIT 1; 
+  ELSEIF (pOrderType = 'TO') THEN
+    SELECT shiphead_number INTO _result
+    FROM shiphead JOIN tohead ON (tohead_id=shiphead_order_id)
+    WHERE (shiphead_order_id=pOrderId)
+      AND (shiphead_order_type='TO') 
+      AND (NOT shiphead_shipped)
+      AND (CASE WHEN (pWarehousId IS NULL) THEN TRUE
+                ELSE tohead_src_warehous_id=pWarehousId END) 
+    ORDER BY shiphead_number
+    LIMIT 1; 
+  END IF;
+
+  RETURN _result;
+
+END;
+$$ LANGUAGE 'plpgsql' STABLE;
+
+CREATE OR REPLACE FUNCTION getOpenShipmentId(pOrderType TEXT,
+                                             pOrderId INTEGER,
+                                             pWarehousId INTEGER) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
+-- See www.xtuple.com/CPAL for the full text of the software license.
+DECLARE
+  _result INTEGER := -1;
+
+BEGIN
+
+  IF (pOrderType = 'SO') THEN
+    SELECT shiphead_id INTO _result
+    FROM shiphead JOIN shipitem ON (shipitem_shiphead_id=shiphead_id)
+                  JOIN coitem ON (coitem_id=shipitem_orderitem_id)
+                  JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
+    WHERE (shiphead_order_id=pOrderId)
+      AND (shiphead_order_type='SO') 
+      AND (NOT shiphead_shipped)
+      AND (CASE WHEN (pWarehousId IS NULL) THEN TRUE
+                ELSE itemsite_warehous_id=pWarehousId END) 
+    ORDER BY shiphead_number
+    LIMIT 1; 
+  ELSEIF (pOrderType = 'TO') THEN
+    SELECT shiphead_id INTO _result
+    FROM shiphead JOIN tohead ON (tohead_id=shiphead_order_id)
+    WHERE (shiphead_order_id=pOrderId)
+      AND (shiphead_order_type='TO') 
+      AND (NOT shiphead_shipped)
+      AND (CASE WHEN (pWarehousId IS NULL) THEN TRUE
+                ELSE tohead_src_warehous_id=pWarehousId END) 
+    ORDER BY shiphead_number
+    LIMIT 1; 
+  END IF;
+
+  RETURN _result;
+
+END;
+$$ LANGUAGE 'plpgsql' STABLE;
index 55cffab..e4467c8 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getOpHeadId(text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pOpHeadName ALIAS FOR $1;
index 04dff18..839a0a1 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getPacklistCharName(INTEGER, INTEGER) RETURNS TEXT AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pShipheadId ALIAS FOR $1;
index ec6b1fc..788e11f 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getPacklistCharValue(INTEGER, INTEGER) RETURNS TEXT AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pShipheadId ALIAS FOR $1;
index c6cbb2f..f73c028 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION getPacklistItemLotSerial(INTEGER, INTEGER) RETURNS TEXT AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pShipheadId ALIAS FOR $1;
index 3e16683..3dbf908 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION getperiodid(INTEGER,  char) RETURNS SETOF INTEGER IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPeriodId ALIAS FOR $1;
@@ -44,7 +44,7 @@ $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION getPeriodId(date)
   RETURNS integer AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPeriodDate ALIAS FOR $1;
index 33a1f6b..e377538 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getPkgheadId(text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   ppkgname ALIAS FOR $1;
index 8a4954d..f4753dd 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getPlanCodeId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPlanCode ALIAS FOR $1;
index 440ce7e..4d776f3 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getPoheadId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPurchaseOrderNumber ALIAS FOR $1;
index 98c031f..928305c 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getPoitemId(text,integer) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPurchaseOrderNumber ALIAS FOR $1;
index 67fd630..7bd5c67 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getPrjAccntId(INTEGER, INTEGER) RETURNS INTEGER IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPrjid ALIAS FOR $1;
index a42ef98..25d8735 100644 (file)
@@ -1,8 +1,7 @@
-CREATE OR REPLACE FUNCTION getPrjId(text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION getPrjId(pPrjNumber text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
-  pPrjNumber ALIAS FOR $1;
   _returnVal INTEGER;
 BEGIN
   IF (pPrjNumber IS NULL) THEN
@@ -19,4 +18,4 @@ BEGIN
 
   RETURN _returnVal;
 END;
-$$ LANGUAGE 'plpgsql' STABLE;
+$$ LANGUAGE 'plpgsql';
index bde40f4..6aa975d 100644 (file)
@@ -1,9 +1,8 @@
-CREATE OR REPLACE FUNCTION getPrjTaskId(text, text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION getPrjTaskId(pPrjNumber text,
+                                        pTaskNumber text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
-  pPrjNumber ALIAS FOR $1;
-  pTaskNumber ALIAS FOR $2;
   _returnVal INTEGER;
 BEGIN
   IF (pPrjNumber IS NULL OR pTaskNumber IS NULL) THEN
@@ -22,4 +21,4 @@ BEGIN
 
   RETURN _returnVal;
 END;
-$$ LANGUAGE 'plpgsql' STABLE;
+$$ LANGUAGE 'plpgsql';
index 51f74e7..3394c95 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getProdCatId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pProdCat ALIAS FOR $1;
index ebe2585..4dbcfaf 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getProspectId(TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pProspectNumber ALIAS FOR $1;
index 7d98ee3..f10784e 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getQuoteId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pQuoteNumber ALIAS FOR $1;
index 6b3f695..279e319 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getQuoteLineItemId(text,integer) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pQuoteNumber ALIAS FOR $1;
diff --git a/foundation-database/public/functions/getquotescheddate.sql b/foundation-database/public/functions/getquotescheddate.sql
new file mode 100644 (file)
index 0000000..4828e7e
--- /dev/null
@@ -0,0 +1,17 @@
+CREATE OR REPLACE FUNCTION getQuoteSchedDate(INTEGER) RETURNS DATE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
+-- See www.xtuple.com/CPAL for the full text of the software license.
+DECLARE
+  pQuheadid ALIAS FOR $1;
+  _minscheddate DATE;
+
+BEGIN
+
+  SELECT MIN(quitem_scheddate) INTO _minscheddate
+  FROM quitem
+  WHERE (quitem_quhead_id=pQuheadid);
+
+  RETURN _minscheddate;
+
+END;
+$$ LANGUAGE 'plpgsql';
index 8d09005..f6876c7 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getRevId(text,text,text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pType ALIAS FOR $1;
index 7f8d65a..63fec64 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getRsnId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pRsnCode ALIAS FOR $1;
index d9c6ad4..472b060 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getSalesCatId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSalesCatName ALIAS FOR $1;
index 86f637d..bc0c7fe 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getSalesLineItemId(TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSalesOrderItem ALIAS FOR $1;
@@ -31,7 +31,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION getSalesLineItemId(TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN getSalesLineItemId($1, $2, 0);
@@ -39,7 +39,7 @@ END
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION getSalesLineItemId(TEXT, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSalesOrderNumber ALIAS FOR $1;
index 80a67e5..fadc148 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getSalesOrderId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSalesOrderNumber ALIAS FOR $1;
index 113d98a..4a6e1aa 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getSalesRepId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSalesRepNumber ALIAS FOR $1;
index a4ea2bd..7941359 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getSaleTypeId(pSaleType TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _returnVal INTEGER;
index f4280fb..710b567 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getShiftId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pShiftNumber ALIAS FOR $1;
index b0dcae9..803108d 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getShipChrgId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pShipChrgName ALIAS FOR $1;
index 5c097d6..6ead5af 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getShipFormId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pShipFormName ALIAS FOR $1;
index 3faf603..bc35d3d 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getShipheadId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pShipmentNumber ALIAS FOR $1;
index 9890b6b..ecc1e68 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getShiptoId(text, text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCustNumber ALIAS FOR $1;
index fb2db7e..a631908 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION getShipToNumberFromInfo(TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, TEXT, BOOLEAN, BOOLEAN) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _custname TEXT := COALESCE(TRIM(UPPER( $1)), '');
index 8361a5a..273b08d 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getShipViaId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pShipViaCode ALIAS FOR $1;
index 6c3551c..f2cab10 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getShipZoneId(pShipZoneName TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _returnVal INTEGER;
index 90c1d98..50e4e89 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getSiteTypeId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSiteType ALIAS FOR $1;
diff --git a/foundation-database/public/functions/getsoitemstatus.sql b/foundation-database/public/functions/getsoitemstatus.sql
new file mode 100644 (file)
index 0000000..62da625
--- /dev/null
@@ -0,0 +1,39 @@
+CREATE OR REPLACE FUNCTION getSoitemStatus(pCoitemid INTEGER) RETURNS TEXT AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
+-- See www.xtuple.com/CPAL for the full text of the software license.
+DECLARE
+  _result TEXT;
+
+BEGIN
+
+  SELECT
+      (CASE WHEN (coitem_status='O' AND (SELECT cust_creditstatus FROM custinfo WHERE cust_id=cohead_cust_id)='H') THEN 'H'
+            WHEN (coitem_status='O' AND ((SELECT SUM(invcitem_billed)
+                                            FROM invchead, invcitem
+                                           WHERE ((CAST(invchead_ordernumber AS text)=cohead_number)
+                                             AND  (invcitem_invchead_id=invchead_id)
+                                             AND  (invcitem_item_id=itemsite_item_id)
+                                             AND  (invcitem_warehous_id=itemsite_warehous_id)
+                                             AND  (invcitem_linenumber=coitem_linenumber))) >= coitem_qtyord)) THEN 'I'
+            WHEN (coitem_status='O' AND ((SELECT SUM(invcitem_billed)
+                                            FROM invchead, invcitem
+                                           WHERE ((CAST(invchead_ordernumber AS text)=cohead_number)
+                                             AND  (invcitem_invchead_id=invchead_id)
+                                             AND  (invcitem_item_id=itemsite_item_id)
+                                             AND  (invcitem_warehous_id=itemsite_warehous_id)
+                                             AND  (invcitem_linenumber=coitem_linenumber))) > 0)) THEN 'P'
+            WHEN (coitem_status='O' AND (itemsite_qtyonhand - qtyAllocated(itemsite_id, CURRENT_DATE)
+                                         + qtyOrdered(itemsite_id, CURRENT_DATE))
+                                          >= ((coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned) * coitem_qty_invuomratio)) THEN 'R'
+            ELSE coitem_status END
+       || CASE WHEN (coitem_firm) THEN 'F' ELSE '' END
+       ) INTO _result
+  FROM coitem JOIN cohead ON (cohead_id=coitem_cohead_id)
+              JOIN custinfo ON (cust_id=cohead_cust_id)
+              JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
+  WHERE (coitem_id=pCoitemid);
+
+  RETURN _result;
+
+END;
+$$ LANGUAGE 'plpgsql' STABLE;
index ef09233..0fd2c08 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getSoSchedDate(INTEGER) RETURNS DATE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCoheadid ALIAS FOR $1;
index 663c327..8419758 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getSoStatus(INTEGER) RETURNS CHAR(1) AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCoheadid ALIAS FOR $1;
index 5bf8f4d..1d4bdc2 100644 (file)
@@ -2,7 +2,7 @@
 CREATE OR REPLACE FUNCTION getsubtax(integer, integer)
   RETURNS SETOF subtax AS
 $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTaxCodeId ALIAS FOR $1;
index 3fadbcd..8717179 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getTaxAuthId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTaxAuthCode ALIAS FOR $1;
index 68edce6..f5a721a 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getTaxId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTaxCode ALIAS FOR $1;
index ba287f3..cb52178 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getTaxTypeId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTaxType ALIAS FOR $1;
index ddc0d2f..e3c4829 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getTaxZoneId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTaxZone ALIAS FOR $1;
index 24e1904..dfe6d16 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getTermsId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTermsCode ALIAS FOR $1;
index bb790f3..3d7ec1e 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION getUnassignedAccntId() RETURNS INTEGER STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _test INTEGER;
index 73b713e..a9b0eab 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getUomId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pUom ALIAS FOR $1;
index cace7b5..a71f624 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getUomTypeId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pUomType ALIAS FOR $1;
@@ -22,7 +22,7 @@ END;
 ' LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION getUomTypeId(text[]) RETURNS INTEGER[] AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pUomTypes ALIAS FOR $1;
index c16b314..837cbb9 100644 (file)
@@ -1,8 +1,7 @@
-CREATE OR REPLACE FUNCTION getUsrId(text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION getUsrId(pUsr text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
-  pUsr ALIAS FOR $1;
   _returnVal INTEGER;
 BEGIN
   SELECT usr_id INTO _returnVal
index bbb6ea8..0d6205c 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getUsrLocaleId() RETURNS INTEGER IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _returnVal INTEGER;
index 741b55b..b663185 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getVendAddrId(text, text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVendNumber   ALIAS FOR $1;
index 88bbd65..bbac992 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getVendId(text) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVendNumber ALIAS FOR $1;
index ef03ff9..146fd53 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getVendTypeId(text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVendTypeCode ALIAS FOR $1;
index a4555de..60a8911 100644 (file)
@@ -1,9 +1,8 @@
-CREATE OR REPLACE FUNCTION getWarehousId(text,text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION getWarehousId(pWarehousCode text,
+                                         pType text) RETURNS INTEGER STABLE AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
-  pWarehousCode ALIAS FOR $1;
-  pType ALIAS FOR $2;
   _active BOOL;
   _shipping BOOL;
   _returnVal INTEGER;
@@ -12,8 +11,8 @@ BEGIN
        RETURN NULL;
   END IF;
  
-  IF (UPPER(pType) NOT IN (''ALL'',''ACTIVE'',''SHIPPING'')) THEN
-       RAISE EXCEPTION ''Warehouse lookip type % not valid. Valid types are ALL, ACTIVE and SHIPPING'', pType;
+  IF (UPPER(pType) NOT IN ('ALL','ACTIVE','SHIPPING')) THEN
+       RAISE EXCEPTION 'Warehouse lookip type % not valid. Valid types are ALL, ACTIVE and SHIPPING', pType;
   END IF;
 
   SELECT warehous_id, warehous_active, warehous_shipping INTO _returnVal, _active, _shipping
@@ -21,15 +20,15 @@ BEGIN
   WHERE (warehous_code=UPPER(pWarehousCode));
 
   IF (_returnVal IS NULL) THEN
-    RAISE EXCEPTION ''Warehouse Code % not found.'', pWarehousCode;
-    ELSE IF ((pType=''SHIPPING'') AND (_shipping=false)) THEN
-      RAISE EXCEPTION ''Warehouse Code % is not a vaild shipping warehouse.'', pWarehousCode;
-      ELSE IF ((pType IN (''SHIPPING'',''ACTIVE'')) AND (_active=false)) THEN
-        RAISE EXCEPTION ''Warehouse Code % is inactive.'', pWarehousCode;
+    RAISE EXCEPTION 'Warehouse Code % not found.', pWarehousCode;
+    ELSE IF ((pType='SHIPPING') AND (_shipping=false)) THEN
+      RAISE EXCEPTION 'Warehouse Code % is not a vaild shipping warehouse.', pWarehousCode;
+      ELSE IF ((pType IN ('SHIPPING','ACTIVE')) AND (_active=false)) THEN
+        RAISE EXCEPTION 'Warehouse Code % is inactive.', pWarehousCode;
       END IF;
     END IF;
   END IF;
 
   RETURN _returnVal;
 END;
-' LANGUAGE 'plpgsql';
+$$ LANGUAGE 'plpgsql';
index 7057d8e..575e7ed 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION getWhseZoneId(text, text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWhseCode ALIAS FOR $1;
index 8a9bd8f..e3d6799 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION grantAllModuleCmnttypeSource(INTEGER, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCmnttypeid ALIAS FOR $1;
index 3925c94..dfd7429 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION grantAllModulePriv(TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pUsername ALIAS FOR $1;
index 7ffdeb7..90f463f 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION grantAllModulePrivGroup(INTEGER, TEXT) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pGrpid ALIAS FOR $1;
index 9e95449..0e2b2d0 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION grantCmnttypeSource(INTEGER, INTEGER) RETURNS BOOL AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCmnttypeid ALIAS FOR $1;
index aa4b382..0fc48cf 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION grantGroup(TEXT, INTEGER) RETURNS BOOL AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pUsername ALIAS FOR $1;
index 1bfd993..bf49fdd 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION grantPriv(TEXT, INTEGER) RETURNS BOOL AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pUsername ALIAS FOR $1;
@@ -30,7 +30,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION grantPriv(TEXT, TEXT) RETURNS BOOL AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pUsername ALIAS FOR $1;
index c5f3641..e342088 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION grantPrivGroup(INTEGER, INTEGER) RETURNS BOOL AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pGrpid ALIAS FOR $1;
index ce22f87..56b5325 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION hasAlarms() RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _alarm          RECORD;
index 464e2ab..314ba3a 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION hasEvents() RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
 
index 0c0b036..78ff687 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION hasMessages() RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
 
index 7627147..553d4dd 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION hasPriv(TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPrivName    ALIAS FOR $1;
index b04d755..0345a4f 100644 (file)
@@ -2,7 +2,7 @@ CREATE OR REPLACE FUNCTION hasPrivOnObject(pPrivType   TEXT,
                                            pObjectType TEXT,
                                            pObjectId   INTEGER = NULL,
                                            pUser       TEXT    = NULL) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _haspriv   BOOLEAN := FALSE;
index b5458f5..d437eff 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION implodeWo(INTEGER, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoid ALIAS FOR $1;
index d333ed7..2e673a9 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION incdt() RETURNS SETOF incdt AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _row incdt%ROWTYPE;
index 01e7fbb..aa707f7 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION indentedBOM(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
@@ -16,7 +16,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION indentedBOM(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
@@ -88,7 +88,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION indentedBOM(INTEGER, INTEGER, INTEGER, INTEGER) RETURNS SETOF bomdata AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index 62da13e..5a42ac0 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION indentedWhereUsed(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
@@ -38,8 +38,7 @@ BEGIN
 
   WHILE ( ( SELECT count(*)
             FROM bomwork
-            WHERE ((bomwork_item_type IN ('M', 'F'))
-              AND (bomwork_status='U')
+            WHERE ((bomwork_status='U')
               AND (bomwork_set_id=_indexid)) ) > 0) LOOP
 
     _level := _level + 1;
@@ -70,8 +69,7 @@ BEGIN
                                AND (CURRENT_DATE BETWEEN bomitem_effective AND (bomitem_expires - 1))
                                AND (bomitem_rev_id=getActiveRevId('BOM',bomitem_parent_item_id)) )
                  JOIN item ON (item_id=bomitem_parent_item_id)
-    WHERE ((bomwork_status='U')
-      AND  (bomwork_item_type IN ('M', 'F')));
+    WHERE (bomwork_status='U');
 
     UPDATE bomwork
     SET bomwork_status='C'
index 4efe0a0..66243e1 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION indentedwo(integer, boolean, boolean, boolean) RETURNS SETOF wodata AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
    pwoid ALIAS FOR $1;
@@ -26,7 +26,7 @@ BEGIN
        SELECT wo_id,wo_number,wo_subnumber,wo_status,wo_startdate,
          wo_duedate,wo_adhoc,wo_itemsite_id,itemsite_qtyonhand,
          wo_qtyord,wo_qtyrcv,wo_prodnotes, item_number,
-         item_descrip1, item_descrip2, uom_name
+         item_descrip1, item_descrip2, item_listprice, uom_name
        FROM wo, itemsite, item, uom     
        WHERE ((wo_id = pwoid)
          AND (itemsite_id = wo_itemsite_id)
@@ -44,7 +44,9 @@ BEGIN
         _row.wodata_startdate := _x.wo_startdate;
         _row.wodata_duedate := _x.wo_duedate;
         _row.wodata_adhoc := _x.wo_adhoc;     
-        _row.wodata_itemsite_id := _x.wo_itemsite_id;         
+        _row.wodata_itemsite_id := _x.wo_itemsite_id;
+        _row.wodata_custprice := _x.item_listprice;
+        _row.wodata_listprice := _x.item_listprice;
         _row.wodata_qoh := _x.itemsite_qtyonhand;
         _row.wodata_short := noneg(_x.wo_qtyord - _x.wo_qtyrcv);
         _row.wodata_qtyrcv := _x.wo_qtyrcv;   
@@ -122,7 +124,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION indentedwo(integer, integer, integer, boolean, boolean) RETURNS SETOF wodata AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
    pwoid ALIAS FOR $1;   
@@ -148,7 +150,7 @@ BEGIN
     --find all WO with the ordid of the next level up
     _qry := 'SELECT wo_id,wo_number,wo_subnumber,wo_status,wo_startdate,wo_duedate,
          wo_adhoc,wo_itemsite_id,itemsite_qtyonhand,wo_qtyord,wo_qtyrcv, wo_prodnotes,
-         item_number,item_descrip1, item_descrip2, uom_name,
+         item_number,item_descrip1, item_descrip2, item_listprice, uom_name,
          womatl_qtyiss, womatl_scrap, womatl_wooper_id
        FROM itemsite,  wo, item, uom, womatl 
        WHERE ((wo_ordid = ' || pwoid || ')
@@ -180,6 +182,8 @@ BEGIN
         _row.wodata_duedate := _x.wo_duedate;
         _row.wodata_adhoc := _x.wo_adhoc;      
         _row.wodata_itemsite_id := _x.wo_itemsite_id;        
+        _row.wodata_custprice := _x.item_listprice;
+        _row.wodata_listprice := _x.item_listprice;
         _row.wodata_qoh := _x.itemsite_qtyonhand;
         _row.wodata_short := noneg(_x.wo_qtyord - _x.wo_qtyrcv);
         _row.wodata_qtyiss := _x.womatl_qtyiss;  
index 9471efb..53042e3 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION indentedwomatl(integer, integer) RETURNS SETOF wodata AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
    pwoid ALIAS FOR $1;   
@@ -19,7 +19,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION indentedwomatl(integer, integer, integer) RETURNS SETOF wodata AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
    pwoid ALIAS FOR $1;  
@@ -42,8 +42,9 @@ BEGIN
       wo_startdate, womatl_duedate, womatl_itemsite_id,
       itemsite_qtyonhand, womatl_qtyreq, womatl_qtyiss,
       womatl_qtyper, womatl_qtyreq, womatl_scrap,
-      womatl_ref, womatl_notes, item_number,
-      item_descrip1, item_descrip2, uom_name
+      womatl_ref, womatl_notes, womatl_price, item_listprice,
+      item_number, item_descrip1, item_descrip2,
+      uom_name
     FROM womatl, wo, itemsite, item, uom
     WHERE ((wo_id = womatl_wo_id)
      AND (wo_id = ' || pwoid || ')
@@ -75,6 +76,8 @@ BEGIN
     _subrow.wodata_startdate := _subx.wo_startdate;
     _subrow.wodata_duedate := _subx.womatl_duedate;
     _subrow.wodata_itemsite_id := _subx.womatl_itemsite_id;    
+    _subrow.wodata_custprice := _subx.womatl_price;
+    _subrow.wodata_listprice := _subx.item_listprice;
     _subrow.wodata_qoh := _subx.itemsite_qtyonhand;
     IF((_subx.itemsite_qtyonhand > (_subx.womatl_qtyreq - _subx.womatl_qtyiss))) THEN
       _subrow.wodata_short := 0;
index 893cd14..217508c 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION initEffectiveXtUser() RETURNS VOID AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   -- Effective users use a temporary table to store the user information
index 50d930e..6c796f7 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION initialDistribution(INTEGER, INTEGER) RETURNS INTEGER  AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index 2e19046..87595e8 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION insertIntoGLSeries(INTEGER, TEXT, TEXT, TEXT, INTEGER, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSequence ALIAS FOR $1;
@@ -22,7 +22,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION insertIntoGLSeries(INTEGER, TEXT, TEXT, TEXT, INTEGER, NUMERIC, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSequence ALIAS FOR $1;
@@ -45,7 +45,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION insertIntoGLSeries(INTEGER, TEXT, TEXT, TEXT, INTEGER, NUMERIC, DATE, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSequence ALIAS FOR $1;
@@ -69,7 +69,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION insertIntoGLSeries(INTEGER, TEXT, TEXT, TEXT, INTEGER, NUMERIC, DATE, TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSequence ALIAS FOR $1;
index 4616ae3..2c57375 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION insertccard(text,boolean,text,bytea,bytea,bytea,bytea,bytea,bytea,bytea,bytea,bytea,bytea,text) RETURNS boolean AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCustomer ALIAS FOR $1;
index 3c70818..82e7f5e 100644 (file)
@@ -1,7 +1,7 @@
 
 
 CREATE OR REPLACE FUNCTION insertFlGroup(INTEGER, INTEGER, INTEGER, INTEGER, BOOLEAN) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pFlheadid  ALIAS FOR $1;
@@ -16,7 +16,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION insertFlGroup(INTEGER, INTEGER, INTEGER, INTEGER, BOOLEAN, CHAR) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pFlheadid  ALIAS FOR $1;
@@ -32,7 +32,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION insertflgroup(INTEGER, INTEGER, INTEGER, INTEGER, BOOLEAN, CHAR, INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pFlheadid  ALIAS FOR $1;
index 8f24435..7301b20 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION insertGLTransaction(TEXT, TEXT, TEXT, TEXT, INTEGER, INTEGER, INTEGER, NUMERIC(12,2), DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSource ALIAS FOR $1;
@@ -26,7 +26,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION insertGLTransaction(TEXT, TEXT, TEXT, TEXT, INTEGER, INTEGER, INTEGER, NUMERIC(12,2), DATE, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSource ALIAS FOR $1;
@@ -54,7 +54,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION insertGLTransaction(INTEGER, TEXT, TEXT, TEXT, TEXT, INTEGER, INTEGER, INTEGER, NUMERIC(12,2), DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pJournalNumber ALIAS FOR $1;
@@ -80,7 +80,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION insertGLTransaction(INTEGER, TEXT, TEXT, TEXT, TEXT, INTEGER, INTEGER, INTEGER, NUMERIC(12,2), DATE, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pJournalNumber ALIAS FOR $1;
@@ -108,7 +108,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION insertGLTransaction(INTEGER, TEXT, TEXT, TEXT, TEXT, INTEGER, INTEGER, INTEGER, NUMERIC(12,2), DATE, BOOLEAN, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pJournalNumber ALIAS FOR $1;
index 735763c..f780dd1 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION insertItemCost(INTEGER, INTEGER, INTEGER, NUMERIC, BOOLEAN) RETURNS INTEGER AS $BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
 pItemId ALIAS FOR $1;
index 8a20788..bc45f98 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION intervalToMinutes(INTERVAL) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT (EXTRACT(DAY FROM $1) * 24 * 60 +
           EXTRACT(HOUR FROM $1) * 60 +
index 9914a3c..6882882 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION invAdjustment(INTEGER, NUMERIC, TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN invAdjustment($1, $2, $3, $4, CURRENT_TIMESTAMP, NULL);
@@ -7,7 +7,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION invAdjustment(INTEGER, NUMERIC, TEXT, TEXT, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN invAdjustment($1, $2, $3, $4, $5, NULL);
@@ -15,7 +15,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION invAdjustment(INTEGER, NUMERIC, TEXT, TEXT, TIMESTAMP WITH TIME ZONE, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid     ALIAS FOR $1;
index 810c435..39de427 100644 (file)
@@ -7,7 +7,7 @@ CREATE OR REPLACE FUNCTION invExpense(pItemsiteid     INTEGER,
                                                       DEFAULT CURRENT_TIMESTAMP,
                                       pPrjid          INTEGER DEFAULT NULL)
   RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _invhistid INTEGER;
index 22637a2..6f44f83 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION invhistSense(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pInvhistId ALIAS FOR $1;
index 00b03b9..e49f563 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION invoiceTotal(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pInvoiceId ALIAS FOR $1;
index 3994b3f..5f2a746 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION invReceipt(INTEGER, NUMERIC, TEXT, TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN invReceipt($1, $2, $3, $4, $5, CURRENT_TIMESTAMP, NULL);
@@ -7,7 +7,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION invReceipt(INTEGER, NUMERIC, TEXT, TEXT, TEXT, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN invReceipt($1, $2, $3, $4, $5, $6, NULL);
@@ -15,7 +15,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION invReceipt(INTEGER, NUMERIC, TEXT, TEXT, TEXT, TIMESTAMP WITH TIME ZONE, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index 0eee1fd..4b51b5e 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION invScrap(INTEGER, NUMERIC, TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN invScrap($1, $2, $3, $4, CURRENT_TIMESTAMP);
@@ -7,7 +7,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION invScrap(INTEGER, NUMERIC, TEXT, TEXT, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN invScrap($1, $2, $3, $4, $5, NULL);
@@ -15,7 +15,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION invScrap(INTEGER, NUMERIC, TEXT, TEXT, TIMESTAMP WITH TIME ZONE, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN invScrap($1, $2, $3, $4, $5, $6, NULL);
@@ -23,7 +23,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION invScrap(INTEGER, NUMERIC, TEXT, TEXT, TIMESTAMP WITH TIME ZONE, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index b515a69..ab7901f 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION isMultiCurr() RETURNS BOOL IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN (SELECT (count(*) > 1)
index 26173e4..6840768 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION isNumeric(TEXT) RETURNS BOOLEAN IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pText ALIAS FOR $1;
index 28bb05a..da849d2 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION issueAllBalanceToShipping(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN issueAllBalanceToShipping('SO', $1, 0, NULL);
@@ -7,7 +7,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION issueAllBalanceToShipping(TEXT, INTEGER, INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pordertype           ALIAS FOR $1;
@@ -19,13 +19,10 @@ DECLARE
 BEGIN
   IF (pordertype = 'SO') THEN
     FOR _s IN SELECT coitem_id,
-                    noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned -
-                          ( SELECT COALESCE(SUM(shipitem_qty), 0)
-                            FROM shipitem, shiphead
-                            WHERE ( (shipitem_orderitem_id=coitem_id)
-                             AND (shipitem_shiphead_id=shiphead_id)
-                             AND (NOT shiphead_shipped)
-                             AND (shiphead_order_type=pordertype) ) ) ) AS balance
+                     CASE WHEN (fetchMetricBool('RequireSOReservations'))
+                          THEN coitem_qtyreserved
+                          ELSE noNeg( coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned - qtyAtShipping('SO', coitem_id) )
+                     END AS _balance
              FROM coitem LEFT OUTER JOIN (itemsite JOIN item ON (itemsite_item_id=item_id)) ON (coitem_itemsite_id=itemsite_id)
              WHERE ( (coitem_status NOT IN ('C','X'))
                 AND (item_type != 'K')
@@ -41,13 +38,8 @@ BEGIN
 
   ELSEIF (pordertype = 'TO') THEN
     FOR _s IN SELECT toitem_id,
-                    noNeg( toitem_qty_ordered - toitem_qty_shipped -
-                          ( SELECT COALESCE(SUM(shipitem_qty), 0)
-                            FROM shipitem, shiphead
-                            WHERE ( (shipitem_orderitem_id=toitem_id)
-                             AND (shipitem_shiphead_id=shiphead_id)
-                             AND (NOT shiphead_shipped)
-                             AND (shiphead_order_type=pordertype) ) ) ) AS balance
+                     noNeg( toitem_qty_ordered - toitem_qty_shipped - qtyAtShipping('TO', toitem_id) )
+                      AS balance
              FROM toitem
              WHERE ( (toitem_status NOT IN ('C','X'))
               AND (toitem_tohead_id=pheadid) ) LOOP
index 9ef5420..1f4510a 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION issueLineBalanceToShipping(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN issueLineBalanceToShipping('SO', $1, NULL);
@@ -7,7 +7,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION issueLineBalanceToShipping(TEXT, INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN issueLineBalanceToShipping($1, $2, $3, 0, NULL);
@@ -15,7 +15,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION issueLineBalanceToShipping(TEXT, INTEGER, TIMESTAMP WITH TIME ZONE, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pordertype           ALIAS FOR $1;
@@ -30,21 +30,15 @@ BEGIN
   _itemlocSeries := COALESCE(pitemlocseries,0);
   
   IF (pordertype = 'SO') THEN
-    SELECT noNeg( coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned - 
-                ( SELECT COALESCE(SUM(shipitem_qty), 0)
-                  FROM shipitem, shiphead
-                  WHERE ((shipitem_orderitem_id=coitem_id)
-                    AND  (shipitem_shiphead_id=shiphead_id)
-                    AND  (NOT shiphead_shipped) ) ) ) INTO _qty
+    SELECT CASE WHEN (fetchMetricBool('RequireSOReservations'))
+                THEN coitem_qtyreserved
+                ELSE noNeg( coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned - qtyAtShipping('SO', coitem_id) )
+           END INTO _qty
     FROM coitem
     WHERE (coitem_id=pitemid);
   ELSEIF (pordertype = 'TO') THEN
-    SELECT noNeg( toitem_qty_ordered - toitem_qty_shipped - 
-                ( SELECT COALESCE(SUM(shipitem_qty), 0)
-                  FROM shipitem, shiphead
-                  WHERE ( (shipitem_orderitem_id=toitem_id)
-                   AND (shipitem_shiphead_id=shiphead_id)
-                   AND (NOT shiphead_shipped) ) ) ) INTO _qty
+    SELECT noNeg( toitem_qty_ordered - toitem_qty_shipped - qtyAtShipping('TO', toitem_id) )
+               INTO _qty
     FROM toitem
     WHERE (toitem_id=pitemid);
   ELSE
index ec92436..41ec8e2 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION issues(TEXT) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTransType ALIAS FOR $1;
index 3eea2a4..0ca7f39 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION issueToShipping(INTEGER, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN issueToShipping('SO', $1, $2, 0, CURRENT_TIMESTAMP);
@@ -7,7 +7,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION issueToShipping(INTEGER, NUMERIC, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN issueToShipping('SO', $1, $2, $3, CURRENT_TIMESTAMP);
@@ -15,7 +15,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION issueToShipping(TEXT, INTEGER, NUMERIC, INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN issueToShipping($1, $2, $3, $4, $5, NULL);
@@ -23,7 +23,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION issueToShipping(TEXT, INTEGER, NUMERIC, INTEGER, TIMESTAMP WITH TIME ZONE, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pordertype           ALIAS FOR $1;
@@ -89,11 +89,9 @@ BEGIN
     END IF; 
   
     SELECT shiphead_id INTO _shipheadid
-    FROM shiphead, coitem
-    WHERE ((shiphead_order_id=coitem_cohead_id)
-      AND  (NOT shiphead_shipped)
-      AND  (coitem_id=pitemid)
-      AND  (shiphead_order_type=pordertype));
+    FROM shiphead, coitem JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
+    WHERE ( (coitem_id=pitemid)
+      AND   (shiphead_number=getOpenShipment(pordertype, coitem_cohead_id, itemsite_warehous_id)) );
     IF (NOT FOUND) THEN
       SELECT NEXTVAL('shiphead_shiphead_id_seq') INTO _shipheadid;
 
@@ -236,12 +234,14 @@ BEGIN
       AND  (itemsite_costcat_id=costcat_id)
       AND  (toitem_id=pitemid) );
 
+    SELECT (invhist_unitcost * invhist_invqty) INTO _value
+    FROM invhist
+    WHERE (invhist_id=_invhistid);
+
     SELECT shiphead_id INTO _shipheadid
-    FROM shiphead, toitem
-    WHERE ((shiphead_order_id=toitem_tohead_id)
-      AND  (NOT shiphead_shipped)
-      AND  (toitem_id=pitemid)
-      AND  (shiphead_order_type=pordertype));
+    FROM shiphead, toitem JOIN tohead ON (tohead_id=toitem_tohead_id)
+    WHERE ( (toitem_id=pitemid)
+      AND   (shiphead_number=getOpenShipment(pordertype, tohead_id, tohead_src_warehous_id)) );
 
     IF (NOT FOUND) THEN
       _shipheadid := NEXTVAL('shiphead_shiphead_id_seq');
@@ -273,16 +273,16 @@ BEGIN
 
     INSERT INTO shipitem
     ( shipitem_shiphead_id, shipitem_orderitem_id, shipitem_qty,
-      shipitem_transdate, shipitem_trans_username, shipitem_value,
-      shipitem_invhist_id )
-    SELECT
-      _shipheadid, pitemid, pQty,
-      _timestamp, getEffectiveXtUser(), invhist_invqty * invhist_unitcost,
-      _invhistid
-    FROM toitem, item, invhist
-    WHERE ((toitem_id=pitemid)
-    AND (item_id=toitem_item_id)
-    AND (invhist_id=_invhistid));
+      shipitem_transdate, shipitem_trans_username, shipitem_invoiced,
+      shipitem_value, shipitem_invhist_id )
+    VALUES
+    ( _shipheadid, pitemid, pQty,
+      _timestamp, getEffectiveXtUser(), FALSE,
+      _value, 
+      CASE WHEN _invhistid = -1 THEN NULL
+           ELSE _invhistid
+      END
+    );
 
   ELSE
     RETURN -11;
index 1b6ad0c..dc79509 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION issueWoMaterial(INTEGER, NUMERIC, INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWomatlid ALIAS FOR $1;
@@ -14,7 +14,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION issueWoMaterial(INTEGER, NUMERIC, INTEGER, BOOLEAN, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWomatlid ALIAS FOR $1;
@@ -42,7 +42,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION issueWoMaterial(INTEGER, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWomatlid ALIAS FOR $1;
@@ -58,7 +58,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION issueWoMaterial(INTEGER, NUMERIC, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWomatlid ALIAS FOR $1;
@@ -74,7 +74,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION issueWoMaterial(INTEGER, NUMERIC, INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN issueWoMaterial($1, $2, $3, $4, NULL);
@@ -82,7 +82,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION issueWoMaterial(INTEGER, NUMERIC, INTEGER, TIMESTAMP WITH TIME ZONE, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWomatlid ALIAS FOR $1;
@@ -167,7 +167,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION issueWoMaterial(INTEGER, NUMERIC, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWomatlid ALIAS FOR $1;
@@ -181,7 +181,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION issueWoMaterial(INTEGER, NUMERIC, BOOLEAN, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWomatlid ALIAS FOR $1;
index d6466d3..c64cc85 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION issueWoMaterialBatch(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoid ALIAS FOR $1;
index 2fdd558..dace951 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION itemAltCapInvRat(INTEGER) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index 0174aff..596ea0f 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION itemAltCapUOM(INTEGER) RETURNS TEXT STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index 0eff3e7..5eba88a 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION itemCapInvRat(INTEGER) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index 6279406..e3d100b 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION itemCapUOM(INTEGER) RETURNS TEXT STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index d40fe81..dfd762c 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION itemCharPrice(INTEGER, INTEGER, TEXT, INTEGER, NUMERIC) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
@@ -14,7 +14,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION itemCharPrice(INTEGER, INTEGER, TEXT, INTEGER, INTEGER, NUMERIC) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
@@ -30,7 +30,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION itemCharPrice(INTEGER, INTEGER, TEXT, INTEGER, INTEGER, NUMERIC, INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
@@ -47,7 +47,7 @@ END;
 $$ LANGUAGE plpgsql;
 
 CREATE OR REPLACE FUNCTION itemCharPrice(INTEGER, INTEGER, TEXT, INTEGER, INTEGER, NUMERIC, INTEGER, DATE) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
@@ -65,7 +65,7 @@ END;
 $$ LANGUAGE plpgsql;
 
 CREATE OR REPLACE FUNCTION itemCharPrice(INTEGER, INTEGER, TEXT, INTEGER, INTEGER, NUMERIC, INTEGER, DATE, DATE) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index 8dcf74c..e7e5659 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION itemCharValue(INTEGER, TEXT) RETURNS TEXT AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index d6eba74..6625b7c 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION itemCost(INTEGER) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index 27bc0d5..4469198 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION itemInventoryUOMInUse(INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index 7db6830..05ab2c2 100644 (file)
@@ -1,5 +1,5 @@
-CREATE OR REPLACE FUNCTION itemInvPriceRat(INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION itemInvPriceRat(INTEGER) RETURNS NUMERIC STABLE AS '
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index b05a18b..f7ef3bc 100644 (file)
@@ -9,7 +9,7 @@ CREATE OR REPLACE FUNCTION itemIpsPrice(pItemid INTEGER,
                                         pEffective DATE,
                                         pAsOf DATE,
                                         pSiteid INTEGER) RETURNS SETOF itemprice AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _row  itemprice%ROWTYPE;
@@ -22,8 +22,15 @@ DECLARE
   _listprice NUMERIC := 0.0;
   _qty NUMERIC;
   _asof DATE;
+  _wholesalepricecosting BOOLEAN := false;
+  _long30markups BOOLEAN := false;
+  _itempricingprecedence BOOLEAN := false;
 
 BEGIN
+  _wholesalepricecosting := fetchMetricBool('WholesalePriceCosting');
+  _long30markups := fetchMetricBool('Long30Markups');
+  _itempricingprecedence := fetchMetricBool('ItemPricingPrecedence');
+
 -- Return the itemPrice in the currency passed in as pCurrid
   _qty := itemuomtouom(pItemid, pQtyUOM, NULL, pQty);
 
@@ -31,8 +38,8 @@ BEGIN
   _asof := COALESCE(pAsOf, CURRENT_DATE);
 
 --  Cache Item, Customer and Shipto
-  SELECT * INTO _item
-  FROM item
+  SELECT item.*, itemCost(itemsite_id) AS invcost INTO _item
+  FROM item LEFT OUTER JOIN itemsite ON (itemsite_item_id=item_id AND itemsite_warehous_id=pSiteid)
   WHERE (item_id=pItemid);
 
   SELECT * INTO _cust
@@ -54,15 +61,26 @@ BEGIN
     currToCurr(ipshead_curr_id, pCurrid, ipsprice_price, pEffective) AS rightprice, ipsitem_type AS righttype
   FROM (
   SELECT ipsitem_ipshead_id AS ipsprice_ipshead_id, ipsitem_type,
-         CASE WHEN ipsitem_type = 'N' THEN (ipsitem_price * itemuomtouomratio(_item.item_id, pPriceUOM, ipsitem_price_uom_id))
-              WHEN ipsitem_type = 'D' THEN noNeg(_item.item_listprice - (_item.item_listprice * ipsitem_discntprcnt) - ipsitem_fixedamtdiscount) * _iteminvpricerat
-              WHEN ipsitem_type = 'M' THEN (_item.item_listcost + (_item.item_listcost * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount) * _iteminvpricerat
+         CASE WHEN (ipsitem_type = 'N') THEN
+               (ipsitem_price * itemuomtouomratio(_item.item_id, pPriceUOM, ipsitem_price_uom_id))
+              WHEN (ipsitem_type = 'D') THEN
+               noNeg(_item.item_listprice - (_item.item_listprice * ipsitem_discntprcnt) - ipsitem_fixedamtdiscount) * _iteminvpricerat
+              WHEN ((ipsitem_type = 'M') AND _long30markups AND _wholesalepricecosting) THEN
+               (_item.item_listcost / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount) * _iteminvpricerat
+              WHEN ((ipsitem_type = 'M') AND _long30markups) THEN
+               (_item.invcost / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount) * _iteminvpricerat
+              WHEN (ipsitem_type = 'M' AND _wholesalepricecosting) THEN
+               (_item.item_listcost + (_item.item_listcost * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount) * _iteminvpricerat
+              WHEN (ipsitem_type = 'M') THEN
+               (_item.invcost + (_item.invcost * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount) * _iteminvpricerat
               ELSE 0.00
          END AS ipsprice_price,
          CASE WHEN (ipsitem_item_id=_item.item_id) THEN itemuomtouom(ipsitem_item_id, ipsitem_qty_uom_id, NULL, ipsitem_qtybreak)
               ELSE ipsitem_qtybreak
          END AS ipsprice_qtybreak,
-         (ipsitem_price_uom_id=COALESCE(pPriceUOM,-1)) AS uommatched
+         (COALESCE(ipsitem_price_uom_id, -1)=COALESCE(pPriceUOM,-1)) AS uommatched,
+         CASE WHEN (_itempricingprecedence) THEN (COALESCE(ipsitem_item_id, -1)=_item.item_id)
+              ELSE true END AS itemmatched
     FROM ipsiteminfo
    WHERE(ipsitem_item_id=_item.item_id) OR (ipsitem_prodcat_id=_item.item_prodcat_id) ) AS
         ipsprice, ipshead, ipsass, sale
@@ -77,7 +95,7 @@ BEGIN
      OR   (ipsass_custtype_id=_cust.cust_custtype_id)
      OR   ((COALESCE(LENGTH(ipsass_custtype_pattern), 0) > 0) AND (_cust.custtype_code ~ ipsass_custtype_pattern)) )
         )
-  ORDER BY uommatched DESC, ipsprice_qtybreak DESC, ipsprice_price ASC
+  ORDER BY itemmatched DESC, uommatched DESC, ipsprice_qtybreak DESC, ipsprice_price ASC
   LIMIT 1;
 
 -- Find the best Price Schedule Price
@@ -94,15 +112,26 @@ BEGIN
              WHEN (COALESCE(LENGTH(ipsass_custtype_pattern), 0) > 0) THEN 5
              ELSE 99
            END AS assignseq,
-           CASE WHEN ipsitem_type = 'N' THEN (ipsitem_price * itemuomtouomratio(_item.item_id, pPriceUOM, ipsitem_price_uom_id))
-                WHEN ipsitem_type = 'D' THEN noNeg(_item.item_listprice - (_item.item_listprice * ipsitem_discntprcnt) - ipsitem_fixedamtdiscount) * _iteminvpricerat
-                WHEN ipsitem_type = 'M' THEN (_item.item_listcost + (_item.item_listcost * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount) * _iteminvpricerat
+           CASE WHEN (ipsitem_type = 'N') THEN
+                 (ipsitem_price * itemuomtouomratio(_item.item_id, pPriceUOM, ipsitem_price_uom_id))
+                WHEN (ipsitem_type = 'D') THEN
+                 noNeg(_item.item_listprice - (_item.item_listprice * ipsitem_discntprcnt) - ipsitem_fixedamtdiscount) * _iteminvpricerat
+                WHEN ((ipsitem_type = 'M') AND _long30markups AND _wholesalepricecosting) THEN
+                 (_item.item_listcost / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount) * _iteminvpricerat
+                WHEN ((ipsitem_type = 'M') AND _long30markups) THEN
+                 (_item.invcost / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount) * _iteminvpricerat
+                WHEN (ipsitem_type = 'M' AND _wholesalepricecosting) THEN
+                 (_item.item_listcost + (_item.item_listcost * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount) * _iteminvpricerat
+                WHEN (ipsitem_type = 'M') THEN
+                 (_item.invcost + (_item.invcost * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount) * _iteminvpricerat
                 ELSE 0.00
            END AS protoprice,
            CASE WHEN (ipsitem_item_id=_item.item_id) THEN itemuomtouom(ipsitem_item_id, ipsitem_qty_uom_id, NULL, ipsitem_qtybreak)
                 ELSE ipsitem_qtybreak
            END AS protoqtybreak,
-           (COALESCE(ipsitem_price_uom_id, -1)=COALESCE(pPriceUOM, -1)) AS uommatched
+           (COALESCE(ipsitem_price_uom_id, -1)=COALESCE(pPriceUOM,-1)) AS uommatched,
+           CASE WHEN (_itempricingprecedence) THEN (COALESCE(ipsitem_item_id, -1)=_item.item_id)
+                ELSE true END AS itemmatched
     FROM ipsass JOIN ipshead ON (ipshead_id=ipsass_ipshead_id)
                 JOIN ipsiteminfo ON (ipsitem_ipshead_id=ipshead_id)
     WHERE ((ipsitem_item_id=_item.item_id) OR (ipsitem_prodcat_id=_item.item_prodcat_id))
@@ -116,7 +145,7 @@ BEGIN
           )
   ) AS proto
   WHERE (protoqtybreak <= pQty)
-  ORDER BY assignseq, protoqtybreak DESC, rightprice
+  ORDER BY assignseq, itemmatched DESC, protoqtybreak DESC, rightprice
   LIMIT 1;
  
   IF (_ips.rightprice IS NOT NULL) THEN
index 2763aba..a798254 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION itemlocdistQty(TEXT, INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTypes ALIAS FOR $1;
@@ -38,7 +38,7 @@ END;
 
 
 CREATE OR REPLACE FUNCTION itemlocdistQty(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pLocationid ALIAS FOR $1;
index dba85dd..2d2e385 100644 (file)
@@ -5,7 +5,7 @@ CREATE OR REPLACE FUNCTION itemPrice(pItemid INTEGER,
                                      pQty NUMERIC,
                                      pCurrid INTEGER,
                                      pEffective DATE) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _item RECORD;
@@ -30,7 +30,7 @@ CREATE OR REPLACE FUNCTION itemPrice(pItemid INTEGER,
                                      pPriceUOM INTEGER,
                                      pCurrid INTEGER,
                                      pEffective DATE) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
 
@@ -48,7 +48,7 @@ CREATE OR REPLACE FUNCTION itemPrice(pItemid INTEGER,
                                      pCurrid INTEGER,
                                      pEffective DATE,
                                      pAsOf DATE) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
 
@@ -67,7 +67,7 @@ CREATE OR REPLACE FUNCTION itemPrice(pItemid INTEGER,
                                      pEffective DATE,
                                      pAsOf DATE,
                                      pSiteid INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _r RECORD;
index 1fbe126..21627cd 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION itemSellingUOM(INTEGER) RETURNS TEXT AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index e5646e7..513402e 100644 (file)
@@ -3,7 +3,7 @@ CREATE OR REPLACE FUNCTION itemsrcPrice(pItemsrcid INTEGER,
                                         pQty NUMERIC,
                                         pCurrid INTEGER,
                                         pEffective DATE) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _price NUMERIC := 0.0;
@@ -23,7 +23,7 @@ CREATE OR REPLACE FUNCTION itemsrcPrice(pItemsrcid INTEGER,
                                         pQty NUMERIC,
                                         pCurrid INTEGER,
                                         pEffective DATE) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _price NUMERIC := 0.0;
index 36f04e6..e6fdd41 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION itemUOMByType(INTEGER, TEXT) RETURNS TEXT STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index f2c590b..3f7e43d 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION itemUOMFractionalByType(INTEGER, TEXT) RETURNS BOOL AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index 2715839..24d212b 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION itemUOMFractionalByUOM(INTEGER, INTEGER) RETURNS BOOL AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index cd0f67a..2c74338 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION itemUOMRatioByType(INTEGER, TEXT) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index 8c042d7..5c06616 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION itemuomtouom(INTEGER, INTEGER, INTEGER, NUMERIC) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN itemuomtouom($1, $2, $3, $4, 'qty');
@@ -11,7 +11,7 @@ CREATE OR REPLACE FUNCTION itemuomtouom(pItemid INTEGER,
                                         pUomidTo INTEGER,
                                         pQtyFrom NUMERIC,
                                         pLocale TEXT) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _uomidFrom INTEGER;
index c1ccdee..ddaad5a 100644 (file)
@@ -1,7 +1,7 @@
 CREATE OR REPLACE FUNCTION itemuomtouomratio(pItemid INTEGER,
                                              pUomidFrom INTEGER,
                                              pUomidTo INTEGER) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _uomidFrom INTEGER;
index 3c481c6..1f45087 100644 (file)
@@ -1,6 +1,5 @@
-
 CREATE OR REPLACE FUNCTION public.login() RETURNS integer AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE 
   _p RECORD;
@@ -12,21 +11,31 @@ BEGIN
 END;
 $$ LANGUAGE 'plpgsql';
 
-CREATE OR REPLACE FUNCTION public.login(boolean) RETURNS integer AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+
+CREATE OR REPLACE FUNCTION login(boolean)
+  RETURNS integer AS
+$BODY$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE 
   _setSearchPath ALIAS FOR $1;
   _p RECORD;
 
 BEGIN
-
-  PERFORM pg_try_advisory_lock(datid::integer, procpid)
+  -- added support for PostgreSQL 9.2.0, Incident 21852
+  IF (compareversion('9.2.0') <= 0)
+  THEN
+    PERFORM pg_try_advisory_lock(datid::integer, pid)
+     FROM pg_stat_activity
+    WHERE(pid = pg_backend_pid());
+  ELSE
+    PERFORM pg_try_advisory_lock(datid::integer, procpid)
      FROM pg_stat_activity
     WHERE(procpid = pg_backend_pid());
+  END IF;
 
   -- This is new to version 9.0 and higher and will error on older versions
-  IF (select CAST(split_part(split_part(version(), ' ', 2),'.',1) AS integer) >= 9) THEN
+  IF (compareversion('9.0.0') <= 0) THEN
     SET bytea_output TO escape;
   END IF;
 
@@ -63,5 +72,8 @@ BEGIN
   RETURN 1;
 
 END;
-$$ LANGUAGE 'plpgsql';
-
+$BODY$
+  LANGUAGE plpgsql VOLATILE
+  COST 100;
+ALTER FUNCTION login(boolean)
+  OWNER TO admin;
index b62539f..1626bf2 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION logout() RETURNS integer AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   PERFORM pg_advisory_unlock(datid::integer, procpid)
index f0eb316..448d138 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION lowerCost(INTEGER, TEXT) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid      ALIAS FOR $1;
@@ -11,7 +11,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION lowerCost(INTEGER, TEXT, BOOLEAN) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index 4f9d0a7..e65f19c 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION maintainBOMWorkspace() RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _test TEXT;
index 96e1ba3..2c44d04 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION markAPCheckASPosted(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RAISE NOTICE ''markAPCheckAsPosted() is deprecated - use markCheckAsPosted() instead'';
index 378b322..9f6e6cb 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION markAPCheckAsPrinted(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RAISE NOTICE ''markAPCheckAsPrinted() is deprecated - use markCheckAsPrinted()'';
index 153ce89..7134890 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION markCheckASPosted(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCheckid ALIAS FOR $1;
index 877550e..dbd06ff 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION markCheckAsPrinted(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCheckid ALIAS FOR $1;
index 972751d..5320c51 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION massExpireBomitem(INTEGER, DATE, TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index 8e6507b..23567e6 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION massReplaceBomitem(INTEGER, INTEGER, DATE, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pNewItemid ALIAS FOR $1;
index 4251ce5..556a909 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION merge2crmaccts(INTEGER, INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSourceId ALIAS FOR $1;
index a5b71ee..a403dfe 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION mergecrmaccts(INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTargetId     ALIAS FOR $1;
index 9f6f0dc..f59bbfb 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION moveBomitemDown(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pBomitemid ALIAS FOR $1;
index c509912..7b1effd 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION moveBomitemUp(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pBomitemid ALIAS FOR $1;
index 8ad0109..b177b9b 100644 (file)
@@ -1,7 +1,7 @@
 CREATE OR REPLACE FUNCTION moveccarddown(int4)
   RETURNS int4 AS
 '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCcardid ALIAS FOR $1;
index 91e7a40..9a8192b 100644 (file)
@@ -1,7 +1,7 @@
 CREATE OR REPLACE FUNCTION moveccardup(int4)
   RETURNS int4 AS
 '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCcardid ALIAS FOR $1;
index 361939b..9c8e01f 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION moveFlGroupDown(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pFlgrpid ALIAS FOR $1;
index 6f28386..0e2be0d 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION moveFlGroupUp(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pFlgrpid ALIAS FOR $1;
index ce62691..f602844 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION moveFlItemDown(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pFlitemid ALIAS FOR $1;
index 40b61af..38dc4e6 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION moveFlItemUp(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pFlitemid ALIAS FOR $1;
index 5e9f2e9..ec76516 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION moveFlSpecDown(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pFlspecid ALIAS FOR $1;
index f0d61ad..a8ca0f1 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION moveFlSpecUp(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pFlspecid ALIAS FOR $1;
index 3f317cd..47ec29e 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION moveScript(INTEGER, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pscriptid ALIAS FOR $1;
index 94a234f..15c12ca 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION moveUiform(INTEGER, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   puiformid ALIAS FOR $1;
index a81757a..0c8d2b5 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION nextPeriodByInterval(INTEGER, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPeriodid ALIAS FOR $1;
index 6fdb0b5..01ee022 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION nextPrSubnumber(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPrNumber ALIAS FOR $1;
index 95e600f..51e8074 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION nextWoSubnumber(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 SELECT COALESCE((MAX(wo_subnumber) + 1), 1)
 FROM wo
index e114cbd..839b957 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION noNeg(NUMERIC) RETURNS NUMERIC IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pValue ALIAS FOR $1;
index efcd388..bba8d1e 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION noPos(NUMERIC) RETURNS NUMERIC IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pValue ALIAS FOR $1;
index 7919c46..437f806 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION normalizeTrialBal(INTEGER, CHARACTER(1)) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTrialbalid ALIAS FOR $1;
index 0c36b99..0b85f95 100644 (file)
@@ -1,12 +1,22 @@
-
 CREATE OR REPLACE FUNCTION numOfDatabaseUsers() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _count INTEGER;
 
 BEGIN
 
+  -- in version 9.2.0 the column "procpid" was changed to just "pid" Incident #21852
+  IF (compareversion('9.2.0') <= 0)
+  THEN
+  SELECT count(*)
+    INTO _count
+    FROM pg_stat_activity, pg_locks
+   WHERE((database=datid)
+     AND (classid=datid)
+     AND (objsubid=2)
+     AND (pg_stat_activity.pid = pg_backend_pid()));
+  ELSE
   SELECT count(*)
     INTO _count
     FROM pg_stat_activity, pg_locks
@@ -14,6 +24,8 @@ BEGIN
      AND (classid=datid)
      AND (objsubid=2)
      AND (procpid = pg_backend_pid()));
+  END IF;
+
   IF (_count IS NULL) THEN
     _count := 0;
   END IF;
@@ -22,4 +34,3 @@ BEGIN
 
 END;
 $$ LANGUAGE 'plpgsql';
-
index 2206289..65244d9 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION numOfServerUsers() RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _count INTEGER;
index b3913d0..6a6b046 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION openAccountingPeriod(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPeriodid ALIAS FOR $1;
index e7ecb6d..903bddb 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION openAccountingYearPeriod(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pYearPeriodId ALIAS FOR $1;
index d6036dd..102c87a 100644 (file)
@@ -1,6 +1,6 @@
 CREATE OR REPLACE FUNCTION openAPItemsValue(pVendid    INTEGER,
                                             pPeriodid  INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _value NUMERIC;
index a9813b7..a68d474 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION openARItemsValue(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCustid ALIAS FOR $1;
index 4f8265d..6c0aba2 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION openRecurringItems(INTEGER, TEXT, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pParentid  ALIAS FOR $1;
index a02f348..e59c851 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION ophead() RETURNS SETOF ophead AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _row ophead%ROWTYPE;
index 3c9ae42..a1ded06 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION orderedByPo(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
@@ -16,7 +16,7 @@ END;
 
 
 CREATE OR REPLACE FUNCTION orderedByPo(INTEGER, DATE, DATE) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index fabe1e3..310c519 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION orderedByWo(INTEGER, INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
@@ -14,7 +14,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION orderedByWo(INTEGER, DATE, DATE) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index c6ef6d1..31ff5e2 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION orderhead() RETURNS SETOF ordhead AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _row ordhead%ROWTYPE;
index 906dc59..6925ebd 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION orderitem() RETURNS SETOF orditem AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _row orditem%ROWTYPE;
index 685a328..3f3e272 100644 (file)
@@ -1,6 +1,6 @@
 CREATE OR REPLACE FUNCTION orderitemData(TEXT, INTEGER, INTEGER) RETURNS SETOF orderitemtype
 AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pOrdertype ALIAS FOR $1;
index e323965..910d69a 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION packageIsEnabled(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT COUNT(*) >= 8
   FROM pg_inherits, pg_class, pg_namespace, pkghead
@@ -11,7 +11,7 @@ $$
 LANGUAGE 'sql';
 
 CREATE OR REPLACE FUNCTION packageIsEnabled(TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT COUNT(*) >= 8
   FROM pg_inherits, pg_class, pg_namespace
index 51bb8d1..72dcdab 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION pkgMayBeModified(NAME) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pschemaname ALIAS FOR $1;
index d6dfb46..6885845 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postAPCheck(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RAISE NOTICE ''postAPCheck() is deprecated - use postCheck() instead'';
@@ -9,7 +9,7 @@ END;
 
 
 CREATE OR REPLACE FUNCTION postAPCheck(INTEGER, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RAISE NOTICE ''postAPCheck() is deprecated - use postCheck() instead'';
index 5c1b7c3..68365d2 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postAPChecks(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
 
index bdfc09b..a898d36 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postAPCreditMemoApplication(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pApopenid ALIAS FOR $1;
@@ -109,11 +109,12 @@ BEGIN
     END IF;
   END IF;
 
-  IF (_src.apopen_accnt_id > -1) THEN
-    _apaccntid := _src.apopen_accnt_id;
-  ELSE 
+-- do not post gain/loss to alternate prepaid
+--  IF (_src.apopen_accnt_id > -1) THEN
+--    _apaccntid := _src.apopen_accnt_id;
+--  ELSE 
     _apaccntid := findAPAccount(_src.apopen_vend_id);
-  END IF;
+--  END IF;
 
   PERFORM insertGLTransaction(fetchJournalNumber('AP-MISC'), 'A/P', 'CM',
                             _src.apopen_docnumber, 'CM Application',
index 829467d..b6867bf 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postApopenItems() RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
 
index d013184..7a37742 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION postARCreditMemoApplication(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pAropenid ALIAS FOR $1;
@@ -10,7 +10,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION postARCreditMemoApplication(INTEGER, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pAropenid ALIAS FOR $1;
index 76db92f..eb60384 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postAropenItems() RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
 
index 8bd41b2..3bd956d 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION postBankAdjustment(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pBankadjid ALIAS FOR $1;
index 93ca86c..da8025a 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION postBankReconciliation(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pBankrecid ALIAS FOR $1;
index ec8fd09..219a07f 100644 (file)
@@ -1,7 +1,7 @@
 CREATE OR REPLACE FUNCTION postbillingselection(integer)
   RETURNS integer AS
 $BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCobmiscid ALIAS FOR $1;
index 57add16..b4388a9 100644 (file)
@@ -1,7 +1,7 @@
 CREATE OR REPLACE FUNCTION postbillingselectionconsolidated(integer)
   RETURNS integer AS
 $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCustid ALIAS FOR $1;
index 5965810..0d308e8 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postBillingSelections() RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
 
@@ -10,7 +10,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION postBillingSelections(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RAISE NOTICE 'postBillingselections(int) has been deprecated.  Please use createInvoices(int).';
@@ -19,7 +19,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION postBillingSelections(INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCustTypeId ALIAS FOR $1;
index 5517479..5fe1b70 100644 (file)
@@ -1,6 +1,6 @@
 CREATE OR REPLACE FUNCTION postCashReceipt(pCashrcptid    INTEGER,
                                            pJournalNumber INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _ccpayid  INTEGER;
index ecb6614..b42dd2d 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postCashReceiptDisc(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCashrcptItemId ALIAS FOR $1;
index 6be4654..85debcf 100644 (file)
@@ -3,7 +3,7 @@ CREATE OR REPLACE FUNCTION postCCcashReceipt(pCCpay   INTEGER,
                                              pdoctype TEXT    DEFAULT NULL,
                                              pamount  NUMERIC DEFAULT NULL) RETURNS INTEGER AS
 $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _aropenid     INTEGER;
index dbe56ca..3659dbb 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postCCcredit(INTEGER, TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCCpay       ALIAS FOR $1;
index d678c65..5b19d62 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postCCVoid(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pccpayid ALIAS FOR $1;
index 5c1b091..9a077d1 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postCheck(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pcheckid             ALIAS FOR $1;
@@ -135,15 +135,19 @@ BEGIN
 
   ELSE
     FOR _r IN SELECT checkitem_amount, checkitem_discount,
-                     CASE WHEN (checkitem_apopen_id IS NOT NULL) THEN
-                       checkitem_amount / apopen_curr_rate
-                     ELSE
-                       currToBase(checkitem_curr_id,
-                                  checkitem_amount,
-                                  COALESCE(checkitem_docdate, _p.checkhead_checkdate)) 
+                     CASE WHEN (checkitem_apopen_id IS NOT NULL AND apopen_doctype='C') THEN
+                            checkitem_amount / apopen_curr_rate * -1.0
+                          WHEN (checkitem_apopen_id IS NOT NULL) THEN
+                            checkitem_amount / apopen_curr_rate
+                          ELSE
+                            currToBase(checkitem_curr_id,
+                                       checkitem_amount,
+                                       COALESCE(checkitem_docdate, _p.checkhead_checkdate)) 
                      END AS checkitem_amount_base,
                      currTocurr(checkitem_curr_id, _p.checkhead_curr_id,
-                                  checkitem_amount,
+                                CASE WHEN (checkitem_apopen_id IS NOT NULL AND apopen_doctype='C') THEN
+                                          checkitem_amount * -1.0
+                                     ELSE checkitem_amount END,
                                   _p.checkhead_checkdate) AS amount_check,
                      apopen_id, apopen_doctype, apopen_docnumber,
                      aropen_id, aropen_doctype, aropen_docnumber,
@@ -219,15 +223,16 @@ BEGIN
       _exchGain := _exchGain + _exchGainTmp;
 
       PERFORM insertIntoGLSeries( _sequence, _t.checkrecip_gltrans_source,
-                                 'CK', CAST(_p.checkhead_number AS TEXT),
+                                  'CK', CAST(_p.checkhead_number AS TEXT),
                                   _t.checkrecip_accnt_id,
-                                  round(_r.checkitem_amount_base, 2) * -1,
+                                  round(_r.checkitem_amount_base, 2) * -1.0,
                                   _p.checkhead_checkdate, _gltransNote, pcheckid );
       IF (_exchGainTmp <> 0) THEN
        PERFORM insertIntoGLSeries( _sequence, _t.checkrecip_gltrans_source,
-                                   'CK', CAST(_p.checkhead_number AS TEXT),
-                                   getGainLossAccntId(_t.checkrecip_accnt_id), round(_exchGainTmp,2),
-                                   _p.checkhead_checkdate, _gltransNote, pcheckid );
+                                   'CK', CAST(_p.checkhead_number AS TEXT),
+                                   getGainLossAccntId(_t.checkrecip_accnt_id),
+                                   round(_exchGainTmp,2),
+                                   _p.checkhead_checkdate, _gltransNote, pcheckid );
       END IF;
 
       _amount_check := (_amount_check + _r.amount_check);
index 1b0f7cc..9ae722c 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postChecks(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pBankaccntid ALIAS FOR $1;
index 8e439ef..409bce6 100644 (file)
@@ -3,7 +3,7 @@ CREATE OR REPLACE FUNCTION postComment(pCmnttypename TEXT,
                                        pSource TEXT,
                                        pSourceid INTEGER,
                                        pText TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _cmnttypeid INTEGER;
@@ -24,7 +24,7 @@ CREATE OR REPLACE FUNCTION postComment(pCmnttypeid INTEGER,
                                        pSource TEXT,
                                        pSourceid INTEGER,
                                        pText TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
 
@@ -38,7 +38,7 @@ CREATE OR REPLACE FUNCTION postComment(pCmnttypeid INTEGER,
                                        pSourceid INTEGER,
                                        pText TEXT,
                                        pPublic BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _commentid INTEGER;
index 119f460..77f189a 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postCost(INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemcostid ALIAS FOR $1;
index b01d8ed..d114776 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postCountSlip(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCntslipid ALIAS FOR $1;
index 04406bb..be98b98 100644 (file)
@@ -1,7 +1,7 @@
 SELECT dropIfExists('FUNCTION', 'postCountTag(integer, boolean, text)', 'public');
 
 CREATE OR REPLACE FUNCTION postCountTag(INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pInvcntid ALIAS FOR $1;
index c6fac13..229fe0e 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postCountTagLocation(INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pInvcntid ALIAS FOR $1;
index 3a7a22e..71c44f0 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postCountTags(INTEGER, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWarehousid ALIAS FOR $1;
index c38c314..ef0ee19 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION postCreditMemo(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCmheadid ALIAS FOR $1;
@@ -18,7 +18,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION postCreditMemo(INTEGER, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCmheadid ALIAS FOR $1;
index 44bbb7f..bf218a2 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION postCreditMemos(BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPostUnprinted ALIAS FOR $1;
@@ -33,7 +33,7 @@ END;
 ' LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION postCreditMemos(BOOLEAN, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPostUnprinted ALIAS FOR $1;
diff --git a/foundation-database/public/functions/postevent.sql b/foundation-database/public/functions/postevent.sql
new file mode 100644 (file)
index 0000000..74e172c
--- /dev/null
@@ -0,0 +1,55 @@
+
+CREATE OR REPLACE FUNCTION postEvent(pEvnttypename TEXT,
+                                     pOrdtype TEXT,
+                                     pOrdid INTEGER,
+                                     pWhsid INTEGER,
+                                     pNumber TEXT,
+                                     pNewValue NUMERIC,
+                                     pOldValue NUMERIC,
+                                     pNewDate DATE,
+                                     pOldDate DATE) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
+-- See www.xtuple.com/CPAL for the full text of the software license.
+DECLARE
+  _evnttypeid INTEGER;
+  _whsid INTEGER;
+
+BEGIN
+  -- Find event type
+  SELECT evnttype_id INTO _evnttypeid
+  FROM evnttype
+  WHERE (evnttype_name=pEvnttypename);
+  IF (NOT FOUND) THEN
+    RAISE EXCEPTION 'Event type % not found.', pEvnttypename;
+  END IF;
+
+  IF (pWhsid IS NULL) THEN
+    -- Find user preferred warehouse
+    SELECT usrpref_value  INTO _whsid
+    FROM usrpref
+    WHERE usrpref_username = getEffectiveXtUser()
+      AND usrpref_name = 'PreferredWarehouse';
+  ELSE
+    _whsid := pWhsid;
+  END IF;
+
+  INSERT INTO evntlog ( evntlog_evnttime, evntlog_evnttype_id,
+                        evntlog_ordtype, evntlog_ord_id,
+                        evntlog_warehous_id, evntlog_number,
+                        evntlog_newvalue, evntlog_oldvalue,
+                        evntlog_newdate, evntlog_olddate,
+                        evntlog_username )
+  SELECT CURRENT_TIMESTAMP, evnttype_id,
+         pOrdtype, pOrdid,
+         _whsid, pNumber,
+         pNewValue, pOldValue,
+         pNewDate, pOldDate,
+         evntnot_username
+  FROM evnttype JOIN evntnot ON ( (evntnot_evnttype_id=evnttype_id) AND
+                                  (evntnot_warehous_id=_whsid) )
+  WHERE (evnttype_id=_evnttypeid);
+
+  RETURN 0;
+
+END
+$$ LANGUAGE 'plpgsql';
index dfe9144..4e772c1 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION postGLSeries(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSequence ALIAS FOR $1;
@@ -16,7 +16,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION postGLSeries(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSequence ALIAS FOR $1;
@@ -32,7 +32,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION postGLSeries(INTEGER, INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSequence            ALIAS FOR $1;
index b7ed2d8..75c7196 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION postGLSeriesNoSumm(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSequence ALIAS FOR $1;
@@ -17,7 +17,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION postGLSeriesNoSumm(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSequence ALIAS FOR $1;
index 60a399c..4dabf47 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION postIntoInvBalance(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pInvhistId ALIAS FOR $1;
index 8890fa7..8e549c1 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION postIntoTrialBalance(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSequence ALIAS FOR $1;
index 929741d..3f4007c 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postInvHist( INTEGER ) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pInvhistId ALIAS FOR $1;
index d2140b9..453f0f1 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postInvoice(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pInvcheadid ALIAS FOR $1;
@@ -15,7 +15,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION postInvoice(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pInvcheadid ALIAS FOR $1;
@@ -34,7 +34,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION postInvoice(INTEGER, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pInvcheadid ALIAS FOR $1;
@@ -673,6 +673,12 @@ BEGIN
           _totalAmount := _totalAmount - currToCurr(_tmpCurrId, _p.invchead_curr_id,
                                                    _appliedAmount, _firstExchDate);
         END IF;
+
+        -- delete the allocation
+        DELETE FROM aropenalloc
+        WHERE (aropenalloc_doctype='I')
+          AND (aropenalloc_doc_id=_p.invchead_id);
+
       END IF;
     END LOOP;
   END IF;
index 0740618..f0120ce 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postInvoices(BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPostUnprinted ALIAS FOR $1;
@@ -10,7 +10,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION postInvoices(BOOLEAN, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPostUnprinted ALIAS FOR $1;
@@ -22,7 +22,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION postInvoices(BOOLEAN, BOOLEAN, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPostUnprinted ALIAS FOR $1;
index 975b78a..6625169 100644 (file)
@@ -14,7 +14,7 @@ CREATE OR REPLACE FUNCTION postInvTrans(pItemsiteId    INTEGER,
                                         pCostOvrld     NUMERIC DEFAULT NULL,
                                         pInvhistid     INTEGER DEFAULT NULL)
   RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 -- pInvhistid is the original transaction to be returned, reversed, etc.
 DECLARE
index c717a99..5dcdc73 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postItemlocSeries(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemlocseries ALIAS FOR $1;
index a188cdd..a9f6c5b 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postJournals(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSequence    ALIAS FOR $1;
@@ -74,7 +74,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION postJournals(TEXT[], DATE, DATE, DATE) RETURNS SETOF INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSources             ALIAS FOR $1;
@@ -93,7 +93,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION postJournals(TEXT, DATE, DATE, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSource              ALIAS FOR $1;
index bab6c20..bf398d9 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION postMessage(TIMESTAMP, TIMESTAMP, TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pScheduled ALIAS FOR $1;
@@ -30,7 +30,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION postMessage(TIMESTAMP, TIMESTAMP, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pScheduled ALIAS FOR $1;
@@ -61,7 +61,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION postMessage(TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pUsername ALIAS FOR $1;
index e397fae..69806bb 100644 (file)
@@ -1,7 +1,7 @@
 CREATE OR REPLACE FUNCTION postMiscCount(pItemsiteid INTEGER,
                                          pQty NUMERIC,
                                          pComments TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index 4888445..637fbd4 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postPoGLTransactions() RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
 
index ada1659..99ce40f 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postPoReceipt(INTEGER, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN postReceipt($1, $2);
index 45e9ab8..d9f4d03 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postPoReceipts(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN postReceipts(''PO'', $1, NULL);
index c61b6d9..f37d696 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION postPoReturnCreditMemo(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPorejectId ALIAS FOR $1;
@@ -11,7 +11,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION postPoReturnCreditMemo(INTEGER, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPorejectId ALIAS FOR $1;
index ef855a4..b5e3638 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postPoReturns(INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPoheadid ALIAS FOR $1;
@@ -143,7 +143,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION postPoReturns(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPoheadid ALIAS FOR $1;
index c4bec75..72b8a3f 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postProduction(INTEGER, NUMERIC, BOOLEAN, INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoid          ALIAS FOR $1;
@@ -188,7 +188,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION postProduction(INTEGER, NUMERIC, BOOLEAN, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RAISE NOTICE 'postProduction(INTEGER, NUMERIC, BOOLEAN, BOOLEAN) is deprecated. please use postProduction(INTEGER, NUMERIC, BOOLEAN, INTEGER, TIMESTAMP WITH TIME ZONE) instead';
@@ -197,7 +197,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION postProduction(INTEGER, NUMERIC, BOOLEAN, BOOLEAN, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RAISE NOTICE 'postProduction(INTEGER, NUMERIC, BOOLEAN, BOOLEAN, INTEGER) is deprecated. please use postProduction(INTEGER, NUMERIC, BOOLEAN, INTEGER, TIMESTAMP WITH TIME ZONE) instead';
@@ -206,7 +206,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION postProduction(INTEGER, NUMERIC, BOOLEAN, BOOLEAN, INTEGER, TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RAISE NOTICE 'postProduction(INTEGER, NUMERIC, BOOLEAN, BOOLEAN, INTEGER, TEXT, TEXT) is deprecated. please use postProduction(INTEGER, NUMERIC, BOOLEAN, INTEGER, TIMESTAMP WITH TIME ZONE) instead';
index 31d8a50..16bd4b1 100644 (file)
@@ -184,7 +184,7 @@ BEGIN
     WHERE (poitem_id=_o.orderitem_id);
 
   ELSEIF ( (_r.recv_order_type = 'RA') AND
-           (_r.itemsite_id = -1 OR _r.itemsite_id IS NULL OR _r.itemsite_controlmethod = 'N') ) THEN
+           (_r.itemsite_id = -1 OR _r.itemsite_id IS NULL) ) THEN
     RAISE NOTICE 'itemsite controlmethod is %, cannot post receipt.', _r.itemsite_controlmethod;
     RETURN -14;        -- otherwise how do we get the accounts?
 
@@ -285,32 +285,51 @@ BEGIN
            FROM rahead, raitem
         WHERE ((rahead_id=raitem_rahead_id)
         AND  (raitem_id=_r.recv_orderitem_id));
-      SELECT postInvTrans(_r.itemsite_id, 'RR',
-                         _recvinvqty,
-                         'S/R',
-                         _r.recv_order_type, _ra.rahead_number::TEXT || '-' || _ra.raitem_linenumber::TEXT,
-                         '',
-                         'Receive Inventory from ' || _ordertypeabbr,
-                         costcat_asset_accnt_id,
-                          CASE WHEN(COALESCE(_ra.raitem_cos_accnt_id, -1) != -1) THEN 
-                                getPrjAccntId(_o.prj_id, _ra.raitem_cos_accnt_id)
-                               WHEN (_ra.raitem_warranty) THEN 
-                                getPrjAccntId(_o.prj_id, resolveCOWAccount(_r.itemsite_id, _ra.rahead_cust_id, _ra.rahead_saletype_id, _ra.rahead_shipzone_id))
-                              ELSE getPrjAccntId(_o.prj_id, resolveCORAccount(_r.itemsite_id, _ra.rahead_cust_id, _ra.rahead_saletype_id, _ra.rahead_shipzone_id))
-                         END,
-                         _itemlocSeries, _glDate, COALESCE(_o.unitcost,stdcost(itemsite_item_id)) * _recvinvqty) INTO _tmp
-      FROM itemsite, costcat
-      WHERE ( (itemsite_costcat_id=costcat_id)
-       AND (itemsite_id=_r.itemsite_id) );
 
-      IF (NOT FOUND) THEN
-           RAISE EXCEPTION 'Could not post inventory transaction: no cost category found for itemsite_id %', _r.itemsite_id;
-      ELSIF (_tmp < -1) THEN -- less than -1 because -1 means it is a none controlled item
-           IF(_tmp = -3) THEN
-           RAISE NOTICE 'The GL trans value was 0 which means we likely do not have a std cost';
-           RETURN -12; -- The GL trans value was 0 which means we likely do not have a std cost
-           END IF;
-      RETURN _tmp;
+      IF (_r.itemsite_controlmethod = 'N') THEN
+        SELECT insertGLTransaction( fetchJournalNumber('GL-MISC'), 
+                                    'S/R', _r.recv_order_type, _o.orderhead_number,
+                                    'Receive Non-Controlled Inventory from ' || _ordertypeabbr,
+                                    costcat_liability_accnt_id,
+                                    getPrjAccntId(_o.prj_id, costcat_exp_accnt_id), -1,
+                                    round((_o.item_unitprice_base * _r.recv_qty),2),
+                                    _glDate::DATE, false ) INTO _tmp
+        FROM itemsite JOIN costcat ON (costcat_id=itemsite_costcat_id)
+        WHERE(itemsite_id=_r.itemsite_id);
+        IF (NOT FOUND) THEN
+          RAISE EXCEPTION 'Could not post inventory transaction: no cost category found for itemsite_id %', _r.itemsite_id;
+--        ELSIF (_tmp < -1) THEN
+--          RETURN _tmp;
+        END IF;
+      ELSE
+        SELECT postInvTrans(_r.itemsite_id, 'RR',
+                            _recvinvqty,
+                            'S/R',
+                            _r.recv_order_type, _ra.rahead_number::TEXT || '-' || _ra.raitem_linenumber::TEXT,
+                            '',
+                            'Receive Inventory from ' || _ordertypeabbr,
+                            costcat_asset_accnt_id,
+                            CASE WHEN(COALESCE(_ra.raitem_cos_accnt_id, -1) != -1) THEN 
+                                  getPrjAccntId(_o.prj_id, _ra.raitem_cos_accnt_id)
+                                 WHEN (_ra.raitem_warranty) THEN 
+                                  getPrjAccntId(_o.prj_id, resolveCOWAccount(_r.itemsite_id, _ra.rahead_cust_id, _ra.rahead_saletype_id, _ra.rahead_shipzone_id))
+                                 ELSE
+                                  getPrjAccntId(_o.prj_id, resolveCORAccount(_r.itemsite_id, _ra.rahead_cust_id, _ra.rahead_saletype_id, _ra.rahead_shipzone_id))
+                            END,
+                            _itemlocSeries, _glDate, COALESCE(_o.unitcost,stdcost(itemsite_item_id)) * _recvinvqty) INTO _tmp
+        FROM itemsite, costcat
+        WHERE ( (itemsite_costcat_id=costcat_id)
+         AND (itemsite_id=_r.itemsite_id) );
+
+        IF (NOT FOUND) THEN
+          RAISE EXCEPTION 'Could not post inventory transaction: no cost category found for itemsite_id %', _r.itemsite_id;
+        ELSIF (_tmp < -1) THEN -- less than -1 because -1 means it is a none controlled item
+          IF(_tmp = -3) THEN
+            RAISE NOTICE 'The GL trans value was 0 which means we likely do not have a std cost';
+            RETURN -12; -- The GL trans value was 0 which means we likely do not have a std cost
+          END IF;
+          RETURN _tmp;
+        END IF;
       END IF;
 
       INSERT INTO rahist (rahist_itemsite_id, rahist_date,
@@ -564,22 +583,15 @@ BEGIN
     IF (_o.pohead_dropship = TRUE) THEN
 
       -- Generate the PoItemDropShipped event
-      INSERT INTO evntlog
-      ( evntlog_evnttime, evntlog_username, evntlog_evnttype_id,
-        evntlog_ordtype, evntlog_ord_id, evntlog_warehous_id, 
-        evntlog_number )
-      SELECT
-        CURRENT_TIMESTAMP, evntnot_username, evnttype_id,
-        'P', _o.orderitem_id, evntnot_warehous_id,
-        (pohead_number || '-' || poitem_linenumber || ': ' || item_number)
-      FROM evntnot JOIN evnttype ON (evntnot_evnttype_id = evnttype_id)
-           JOIN itemsite ON (evntnot_warehous_id = itemsite_warehous_id) 
-           JOIN item ON (itemsite_item_id = item_id)
-           JOIN poitem ON (poitem_itemsite_id = itemsite_id)
-           JOIN pohead ON (poitem_pohead_id = pohead_id)
-      WHERE( (poitem_id = _o.orderitem_id)
-      AND (poitem_duedate <= (CURRENT_DATE + itemsite_eventfence))
-      AND (evnttype_name = 'PoItemDropShipped') );
+      PERFORM postEvent('PoItemDropShipped', 'P', poitem_id,
+                        itemsite_warehous_id,
+                        (pohead_number || '-' || poitem_linenumber || ': ' || item_number),
+                        NULL, NULL, NULL, NULL)
+      FROM poitem JOIN itemsite ON (itemsite_id=poitem_itemsite_id)
+                  JOIN item ON (item_id=itemsite_item_id)
+                  JOIN pohead ON (pohead_id=poitem_pohead_id)
+      WHERE (poitem_id=_o.orderitem_id)
+        AND (poitem_duedate <= (CURRENT_DATE + itemsite_eventfence));
 
     END IF;
   END IF;
index 6f284ef..2bd0936 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postReceipts(TEXT, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pordertype           ALIAS FOR $1;
index 2db28c0..5194399 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postSoGLTransactions() RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
 
index 1ee42dc..f2bd276 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postSoItemProduction(INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSoitemId      ALIAS FOR $1;
@@ -23,7 +23,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION postSoItemProduction(INTEGER, NUMERIC, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSoitemId ALIAS FOR $1;
index 752abe7..78602bd 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION postStandardJournal(INTEGER, DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pStdjrnlid ALIAS FOR $1;
@@ -17,7 +17,7 @@ END;
 ' LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION postStandardJournal(INTEGER, DATE, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pStdjrnlid ALIAS FOR $1;
@@ -33,7 +33,7 @@ END;
 ' LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION postStandardJournal(INTEGER, DATE, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pStdjrnlid ALIAS FOR $1;
@@ -48,7 +48,7 @@ END;
 ' LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION postStandardJournal(INTEGER, DATE, BOOLEAN, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pStdjrnlid ALIAS FOR $1;
index af54d2e..2381976 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION postStandardJournalGroup(INTEGER, DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pStdjrnlgrpid ALIAS FOR $1;
@@ -11,7 +11,7 @@ END;
 ' LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION postStandardJournalGroup(INTEGER, DATE, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pStdjrnlgrpid ALIAS FOR $1;
index fed503c..e0ef1c3 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postValueintoInvBalance(INTEGER, DATE, NUMERIC, NUMERIC, NUMERIC, NUMERIC) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteId ALIAS FOR $1;
index bc8dd3d..f7b8bd0 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postVoucher(INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVoheadid ALIAS FOR $1;
@@ -12,7 +12,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION postVoucher(INTEGER, INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVoheadid ALIAS FOR $1;
index 641e7a2..f6c48dc 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION postVouchers(BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPostCosts ALIAS FOR $1;
index f960e86..f9f60c9 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION primaryKeyFields(TEXT, TEXT) RETURNS TEXT[] AS $$ 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSchema       ALIAS FOR $1;
index 21839e1..5036d54 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION prj() RETURNS SETOF prj AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _row prj%ROWTYPE;
index eccd458..f27f579 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION prjtask() RETURNS SETOF prjtask AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _row prjtask%ROWTYPE;
index 653f32a..0d205ec 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION purgeCreditMemos(DATE) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCutoffDate ALIAS FOR $1;
index bf37b0a..ede1d9a 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION purgecrmacctmerge(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pDestid       ALIAS FOR $1;
index 36b69ea..9387acc 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION purgeInvoiceRecord(DATE, INTEGER) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCutoffDate ALIAS FOR $1;
index 16498c4..a157233 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION purgeInvoiceRecords(DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCutoffDate ALIAS FOR $1;
index 5d4b0f4..2e37126 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION purgePostedCountSlips(DATE, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCutoffDate ALIAS FOR $1;
index c0da23a..010c1f7 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION purgePostedCountTags(DATE, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCutoffDate ALIAS FOR $1;
index fab0524..65433e2 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION purgeShipments(DATE) RETURNS INTEGER  AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pcutoff ALIAS FOR $1;
index 655e023..43c8203 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION qtyAllocated(INTEGER, INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
@@ -14,7 +14,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION qtyAllocated(INTEGER, DATE) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
@@ -29,7 +29,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION qtyAllocated(INTEGER, DATE, DATE) RETURNS NUMERIC STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index 2206c52..a6859d5 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION qtyAtShipping(INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN qtyAtShipping('SO', $1);
@@ -7,7 +7,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION qtyAtShipping(TEXT, INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN qtyAtShipping($1, $2, 'U');
@@ -15,7 +15,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION qtyAtShipping(TEXT, INTEGER, TEXT) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pordertype   ALIAS FOR $1;
index 487599e..5ccbbea 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION qtyAvailable(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
@@ -17,7 +17,7 @@ END;
 
 
 CREATE OR REPLACE FUNCTION qtyAvailable(INTEGER, DATE) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index 3f83717..39a58e0 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION qtyInShipment(TEXT, INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pordertype   ALIAS FOR $1;
index d28ac04..aabc707 100644 (file)
@@ -1,7 +1,7 @@
 SELECT dropIfExists('FUNCTION','qtyLocation(INTEGER, INTEGER, DATE, DATE, INTEGER, TEXT, INTEGER)');
 
 CREATE OR REPLACE FUNCTION qtyLocation(INTEGER, INTEGER, DATE, DATE, INTEGER, TEXT, INTEGER, INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pLocationId  ALIAS FOR $1;
@@ -39,13 +39,13 @@ BEGIN
      AND (COALESCE(ls.itemlocdist_warranty, endoftime())=COALESCE(pWarranty, ls.itemlocdist_warranty, endoftime()))
      AND (ls.itemlocdist_id != pItemlocdistId ) );
 
--- Summarize itemlocrsrv qty for this location/itemsite
+-- Summarize reserved qty for this location/itemsite
 -- that is reserved for a different order
   IF (fetchMetricBool('EnableSOReservationsByLocation')) THEN
-    SELECT COALESCE(SUM(itemlocrsrv_qty), 0) INTO _qtyReserved
-      FROM itemloc JOIN itemlocrsrv ON ( (itemlocrsrv_itemloc_id=itemloc_id)
-                                    AND  ((itemlocrsrv_source <> COALESCE(pOrderType, '')) OR
-                                          (itemlocrsrv_source_id <> COALESCE(pOrderId, -1))) )
+    SELECT COALESCE(SUM(reserve_qty), 0) INTO _qtyReserved
+      FROM itemloc JOIN reserve ON ( (reserve_supply_id=itemloc_id AND reserve_supply_type='I')
+                                    AND  ((reserve_demand_type <> COALESCE(pOrderType, '')) OR
+                                          (reserve_demand_id <> COALESCE(pOrderId, -1))) )
      WHERE ( (itemloc_itemsite_id=pItemsiteId)
        AND (itemloc_location_id=pLocationId)
        AND (COALESCE(itemloc_ls_id, -1)=COALESCE(pLsId, itemloc_ls_id, -1))
index 8b3d713..a497cca 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION qtyOrdered(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
@@ -16,7 +16,7 @@ END;
 
 
 CREATE OR REPLACE FUNCTION qtyOrdered(INTEGER, DATE) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
@@ -31,7 +31,7 @@ END;
 
 
 CREATE OR REPLACE FUNCTION qtyOrdered(INTEGER, DATE, DATE) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index faa5160..2898ed4 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION qtypr(integer, integer) RETURNS numeric AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
@@ -12,7 +12,7 @@ END;
 $$ LANGUAGE 'plpgsql' VOLATILE;
 
 CREATE OR REPLACE FUNCTION qtypr(integer, date) RETURNS numeric AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
@@ -24,7 +24,7 @@ END;
 $$ LANGUAGE 'plpgsql' VOLATILE;
 
 CREATE OR REPLACE FUNCTION qtypr(integer, date, date) RETURNS numeric AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
diff --git a/foundation-database/public/functions/qtyreserved.sql b/foundation-database/public/functions/qtyreserved.sql
new file mode 100644 (file)
index 0000000..a58681f
--- /dev/null
@@ -0,0 +1,16 @@
+CREATE OR REPLACE FUNCTION qtyReserved(INTEGER) RETURNS NUMERIC AS '
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
+-- See www.xtuple.com/EULA for the full text of the software license.
+DECLARE
+  pItemsiteid ALIAS FOR $1;
+  _qty NUMERIC;
+
+BEGIN
+
+  SELECT COALESCE(SUM(coitem_qtyreserved),0) INTO _qty
+    FROM coitem
+   WHERE(coitem_itemsite_id=pItemsiteid);
+
+  RETURN _qty;
+END;
+' LANGUAGE 'plpgsql';
index b536879..a092df8 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION qtyToReceive(TEXT, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pordertype   ALIAS FOR $1;
index 6d49226..f1bcaec 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION recallShipment(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN recallShipment($1, CURRENT_TIMESTAMP);
@@ -7,7 +7,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION recallShipment(INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pshipheadid          ALIAS FOR $1;
index 6ec3269..3981f7a 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION recallWo(INTEGER, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoid ALIAS FOR $1;
index e9593e1..c0f2092 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION receipts(TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTransType ALIAS FOR $1;
index 2e35ed4..64b171d 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION releaseAPMemoNumber(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT releaseNumber('APMemoNumber', $1::INTEGER) > 0;
 $$ LANGUAGE 'sql';
index 81089ab..5a66f2c 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION releaseARMemoNumber(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   select releaseNumber('ARMemoNumber', $1::INTEGER) > 0;
 $$ LANGUAGE 'sql';
index 3724a2c..c236bc5 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION releaseCashRcptNumber(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT releaseNumber('CashRcptNumber', $1) > 0;
 $$ LANGUAGE 'sql';
index 9fe486e..c067434 100644 (file)
@@ -1,11 +1,11 @@
 CREATE OR REPLACE FUNCTION releaseCMNumber(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT releaseNumber('CmNumber', $1) > 0;
 $$ LANGUAGE sql;
 
 CREATE OR REPLACE FUNCTION releaseCMNumber(TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT releaseNumber('CmNumber', $1::INTEGER) > 0;
 $$ LANGUAGE sql;
index acafc55..376d797 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION releaseCRMAccountNumber(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT releaseNumber('CRMAccountNumber', $1::INTEGER) > 0;
 $$ LANGUAGE sql;
index 62e202e..b95fb37 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION releaseIncidentNumber(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT releaseNumber('IncidentNumber', $1) = 1;
 $$ LANGUAGE sql;
index 94b71b6..3f6ee18 100644 (file)
@@ -1,11 +1,11 @@
 CREATE OR REPLACE FUNCTION releaseInvcNumber(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT releaseNumber('InvcNumber', $1) > 0;
 $$ LANGUAGE sql;
 
 CREATE OR REPLACE FUNCTION releaseInvcNumber(TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT releaseNumber('InvcNumber', $1::INTEGER) > 0;
 $$ LANGUAGE sql;
index 590f607..f72c557 100644 (file)
@@ -1,12 +1,14 @@
 CREATE OR REPLACE FUNCTION releaseNumber(TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   psequence    ALIAS FOR $1;
   pnumber      ALIAS FOR $2;
 BEGIN
-  -- drop the number back into the pool if it was not committed
-  PERFORM clearNumberIssue(psequence, pnumber);
+  IF (fetchMetricBool('EnableGaplessNumbering')) THEN
+    -- drop the number back into the pool if it was not committed
+    PERFORM clearNumberIssue(psequence, pnumber);
+  END IF;
   
   UPDATE orderseq SET
     orderseq_number = LEAST(pnumber, orderseq_number)
index 93b62a1..90a0875 100644 (file)
@@ -1,12 +1,12 @@
 CREATE OR REPLACE FUNCTION releasePoNumber(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT releaseNumber('PoNumber', $1) > 0;
 $$ LANGUAGE 'sql';
 
 
 CREATE OR REPLACE FUNCTION releasePoNumber(TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT releaseNumber('PoNumber', $1::INTEGER) > 0;
 $$ LANGUAGE 'sql';
index 5702863..0cad850 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION releasePrNumber(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT releaseNumber('PrNumber', $1) > 0;
 $$ LANGUAGE 'sql';
index 4d409cb..6adf3b8 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION releasePurchaseOrder(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPoheadid ALIAS FOR $1;
index 2049453..adefc34 100644 (file)
@@ -1,11 +1,11 @@
 CREATE OR REPLACE FUNCTION releaseQuNumber(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT releaseNumber('QuNumber', $1);
 $$ LANGUAGE 'sql';
 
 CREATE OR REPLACE FUNCTION releaseQuNumber(TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT releaseNumber('QuNumber', $1::INTEGER);
 $$ LANGUAGE 'sql';
index 419fd6d..a95e105 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION releaseShipmentNumber(INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pNumber ALIAS FOR $1;
index e6f3039..ed0a68c 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION releaseSohead(INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSoheadid ALIAS FOR $1;
index dc10690..9988c3b 100644 (file)
@@ -1,11 +1,11 @@
 CREATE OR REPLACE FUNCTION releaseSoNumber(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT releaseNumber('SoNumber', $1);
 $$ LANGUAGE 'sql';
 
 CREATE OR REPLACE FUNCTION releaseSoNumber(TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
        IF (COALESCE($1, '') = '' OR $1 ~ '[^0-9]')
index d2760a1..04bbc1e 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION releaseUnusedBillingHeader(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCobmiscid ALIAS FOR $1;
index fabba2c..6d9ccd7 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION releaseVoNumber(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT releaseNumber('VcNumber', $1) > 0;
 $$ LANGUAGE 'sql';
index 62cd8c7..8653317 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION releaseWo(INTEGER, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoid ALIAS FOR $1;
index 69139f8..00c4c27 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION releaseWoNumber(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT releaseNumber('WoNumber', $1) > 0;
 $$ LANGUAGE 'sql';
index 81b736c..29823d9 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION relocateInventory(INTEGER, INTEGER, INTEGER, NUMERIC, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN relocateInventory($1, $2, $3, $4, $5, CURRENT_TIMESTAMP);
@@ -7,7 +7,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION relocateInventory(INTEGER, INTEGER, INTEGER, NUMERIC, TEXT, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSourceItemlocid      ALIAS FOR $1;
@@ -18,9 +18,13 @@ DECLARE
   _GlDistTS             TIMESTAMP WITH TIME ZONE := $6;
   _targetItemlocid      INTEGER;
   _invhistid            INTEGER;
-  _p RECORD;
-  _qty NUMERIC;
-  _itemlocSeries INTEGER := NEXTVAL('itemloc_series_seq');
+  _p                    RECORD;
+  _rsrv                 RECORD;
+  _qty                  NUMERIC;
+  _qtyunreserved        NUMERIC := 0.0;
+  _qtytomove            NUMERIC := 0.0;
+  _result               INTEGER := -1;
+  _itemlocSeries        INTEGER := NEXTVAL('itemloc_series_seq');
 
 BEGIN
 
@@ -96,11 +100,6 @@ BEGIN
    AND (NOT itemsite_freeze)
    AND (itemloc_id=pSourceItemlocid) );
 
---  Check to see if there is anything left at the source Itemloc and delete if not
-  DELETE FROM itemloc
-  WHERE ( (itemloc_qty=0)
-   AND (itemloc_id=pSourceItemlocid) );
-
 --  Check to see if any of the current Lot/Serial #/Expiration exists at the target location
   SELECT itemloc_id INTO _targetItemlocid
   FROM itemloc 
@@ -184,6 +183,56 @@ BEGIN
   WHERE ( (itemloc_qty=0)
    AND (itemloc_id=_targetItemlocid) );
 
+--  Handle Reservations
+  IF (fetchMetricBool('EnableSOReservationsByLocation')) THEN
+    SELECT CASE WHEN (qtyReservedLocation(itemloc_id) > itemloc_qty)
+                THEN (qtyReservedLocation(itemloc_id) - itemloc_qty)
+                ELSE 0.0
+                END INTO _qtyunreserved
+    FROM itemloc
+    WHERE (itemloc_id=pSourceItemlocid);
+    -- Move reservations as necessary
+    WHILE (_qtyunreserved > 0.0) LOOP
+      SELECT * INTO _rsrv
+      FROM reserve
+      WHERE ((reserve_supply_type='I')
+        AND  (reserve_supply_id=pSourceItemlocid))
+      ORDER BY reserve_qty;
+      IF (NOT FOUND) THEN
+        RAISE EXCEPTION 'Cannot find reservation to unreserve.';
+      END IF;
+      IF (_rsrv.reserve_qty > _qtyunreserved) THEN
+        _qtytomove := _qtyunreserved;
+      ELSE
+        _qtytomove := _rsrv.reserve_qty;
+      END IF;
+      -- Unreserve Source Location
+      SELECT unreserveSOLineQty(_rsrv.reserve_demand_id,
+                                _qtytomove,
+                                pSourceItemlocid) INTO _result;
+      IF (_result < 0) THEN
+        RAISE EXCEPTION 'unreserveSOLineQty failed with result=%, reserve_id=%, qty=%',
+                        _result, _rsrv.reserve_id, _qtytomove;
+      END IF;
+      -- Reserve to new Location
+      SELECT reserveSOLineQty(_rsrv.reserve_demand_id,
+                              TRUE,
+                              _qtytomove,
+                              _targetItemlocid) INTO _result;
+      IF (_result < 0) THEN
+        RAISE EXCEPTION 'reserveSOLineQty failed with result=%, reserve_id=%, qty=%',
+                        _result, _rsrv.reserve_id, _qtytomove;
+      END IF;
+      -- Calculate running total
+      _qtyunreserved := _qtyunreserved - _qtytomove;
+    END LOOP;
+  END IF;
+
+--  Check to see if there is anything left at the source Itemloc and delete if not
+  DELETE FROM itemloc
+  WHERE ( (itemloc_qty=0)
+   AND (itemloc_id=pSourceItemlocid) );
+
 --  Return the invhist_id
   RETURN _invhistid;
 
diff --git a/foundation-database/public/functions/reopenbankreconciliation.sql b/foundation-database/public/functions/reopenbankreconciliation.sql
new file mode 100644 (file)
index 0000000..1b8fb07
--- /dev/null
@@ -0,0 +1,66 @@
+
+CREATE OR REPLACE FUNCTION reopenBankReconciliation(INTEGER) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
+-- See www.xtuple.com/CPAL for the full text of the software license.
+DECLARE
+  pBankrecid ALIAS FOR $1;
+  _bankrecid INTEGER;
+  _accntid INTEGER;
+  _sequence INTEGER;
+  _gltransid INTEGER;
+  _r RECORD;
+
+BEGIN
+
+-- Check the accnt information to make sure it is valid
+  SELECT accnt_id INTO _accntid
+    FROM bankrec, bankaccnt, accnt
+   WHERE ( (bankaccnt_accnt_id=accnt_id)
+     AND   (bankrec_bankaccnt_id=bankaccnt_id)
+     AND   (bankrec_id=pBankrecid) );
+  IF ( NOT FOUND ) THEN
+    RETURN -1;
+  END IF;
+
+  SELECT bankrec_id INTO _bankrecid
+    FROM bankrec
+   WHERE (NOT bankrec_posted);
+  IF (FOUND) THEN
+  -- Delete any bankrecitem records for unposted periods
+    DELETE FROM bankrecitem
+     WHERE (bankrecitem_bankrec_id=_bankrecid);
+  -- Delete any bankrec records for unposted period
+    DELETE FROM bankrec
+     WHERE (bankrec_id=_bankrecid);
+  END IF;
+
+-- Mark all the gltrans items that have been cleared as unreconciled.
+  UPDATE gltrans
+     SET gltrans_rec = FALSE
+   WHERE ( (gltrans_id IN (SELECT bankrecitem_source_id
+                             FROM bankrecitem
+                            WHERE ((bankrecitem_source = 'GL')
+                              AND  (bankrecitem_cleared)
+                              AND  (bankrecitem_bankrec_id=pBankrecid) ) ) )
+     AND   (gltrans_accnt_id=_accntid) ) ;
+
+-- Mark all the sltrans items that have been cleared as unreconciled.
+  UPDATE sltrans
+     SET sltrans_rec = FALSE
+   WHERE ( (sltrans_id IN (SELECT bankrecitem_source_id
+                             FROM bankrecitem
+                            WHERE ((bankrecitem_source = 'SL')
+                              AND  (bankrecitem_cleared)
+                              AND  (bankrecitem_bankrec_id=pBankrecid) ) ) )
+     AND   (sltrans_accnt_id=_accntid) ) ;
+
+-- Mark the bankrec record as unposted
+  UPDATE bankrec SET 
+    bankrec_posted = FALSE,
+    bankrec_postdate = NULL
+   WHERE (bankrec_id=pBankrecid);
+
+  RETURN pBankrecid;
+END;
+$$ LANGUAGE 'plpgsql';
+
index 268028f..1cbb6eb 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION reorderDate(INTEGER, INTEGER, BOOL) RETURNS DATE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index eb0d068..3448322 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION replaceAllVoidedAPChecks(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RAISE NOTICE ''replaceAllVoidedAPChecks() is deprecated - use replaceAllVoidedChecks() instead'';
index f8d22d1..d463574 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION replaceAllVoidedChecks(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pBankaccntid ALIAS FOR $1;
index 6e715ad..40d8ae7 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION replaceVoidedAPCheck(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RAISE NOTICE ''replaceVoidedAPCheck() is deprecated - use replaceVoidedCheck()'';
index e101d44..1ffaabf 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION replaceVoidedCheck(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCheckid     ALIAS FOR $1;
index e1c365b..d6f14ac 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION reprioritizeWo(INTEGER, INTEGER, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoid ALIAS FOR $1;
index d3aa9b9..ef59de9 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION resetDBObjPerms(TEXT) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pObjname      ALIAS FOR $1;
@@ -12,7 +12,7 @@ END;
 ' LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION resetDBObjPerms() RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _count        INTEGER := 0;
index e27e2a0..abe4fc8 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION resetLowLevelCode(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
 
index 22789ac..b4299f2 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION resetQOHBalance(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN resetQOHBalance($1, CURRENT_TIMESTAMP);
@@ -7,7 +7,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION resetQOHBalance(INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid   ALIAS FOR $1;
index 55571a8..852b23f 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION resolveCOSAccount(INTEGER, INTEGER) RETURNS INTEGER STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
 
@@ -12,7 +12,7 @@ CREATE OR REPLACE FUNCTION resolveCOSAccount(pItemsiteid INTEGER,
                                              pCustid INTEGER,
                                              pSaletypeid INTEGER,
                                              pShipzoneid INTEGER) RETURNS INTEGER STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _salesaccntid INTEGER;
index b0642bc..fb263e1 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION resolveCOWAccount(INTEGER, INTEGER) RETURNS INTEGER STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
 
@@ -12,7 +12,7 @@ CREATE OR REPLACE FUNCTION resolveCOWAccount(pItemsiteid INTEGER,
                                              pCustid INTEGER,
                                              pSaletypeid INTEGER,
                                              pShipzoneid INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _salesaccntid INTEGER;
index 308ab46..0d92313 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION resolveCreditAccount(INTEGER, INTEGER) RETURNS INTEGER STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
 
@@ -12,7 +12,7 @@ CREATE OR REPLACE FUNCTION resolveCreditAccount(pItemsiteid INTEGER,
                                                 pCustid INTEGER,
                                                 pSaletypeid INTEGER,
                                                 pShipzoneid INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _salesaccntid INTEGER;
index 621219f..9c51fcd 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION resolveSalesAccount(INTEGER, INTEGER) RETURNS INTEGER STABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
 
@@ -12,7 +12,7 @@ CREATE OR REPLACE FUNCTION resolveSalesAccount(pItemsiteid INTEGER,
                                                pCustid INTEGER,
                                                pSaletypeid INTEGER,
                                                pShipzoneid INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _salesaccntid INTEGER;
index 389e785..b6d4043 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION restoreSalesHistory(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pAsohistid ALIAS FOR $1;
index 06e4ded..c3d53f8 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION returnCompleteShipment(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN returnCompleteShipment($1, 0, CURRENT_TIMESTAMP);
@@ -7,7 +7,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION returnCompleteShipment(INTEGER, INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pshipheadid          ALIAS FOR $1;
index ffbe541..6251630 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION returnItemShipments(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN returnItemShipments('SO', $1, 0, CURRENT_TIMESTAMP);
@@ -8,7 +8,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION returnItemShipments(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN returnItemShipments('SO', $1, $2, CURRENT_TIMESTAMP);
@@ -16,7 +16,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION returnItemShipments(TEXT, INTEGER, INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pordertype           ALIAS FOR $1;
index 5e57792..14db69a 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION returnShipmentTransaction(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN returnShipmentTransaction($1, 0, CURRENT_TIMESTAMP);
@@ -8,7 +8,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION returnShipmentTransaction(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN returnShipmentTransaction($1, $2, CURRENT_TIMESTAMP);
@@ -16,7 +16,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION returnShipmentTransaction(INTEGER, INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pShipitemId           ALIAS FOR $1;
@@ -24,7 +24,7 @@ DECLARE
   pTimestamp            ALIAS FOR $3;
   _itemlocSeries        INTEGER;
   _invhistid            INTEGER;
-  _itemlocrsrvid        INTEGER;
+  _reserveid            INTEGER;
   _coheadid             INTEGER;
   _rows                 INTEGER;
   _r                    RECORD;
@@ -168,10 +168,11 @@ BEGIN
           WHERE (shipitemlocrsrv_shipitem_id=_r.shipitem_id)
         LOOP
           -- See if a reservation record still exists
-          SELECT itemlocrsrv_id, itemlocrsrv_qty INTO _itemlocrsrvid
-          FROM itemlocrsrv JOIN itemloc ON (itemlocrsrv_itemloc_id=itemloc_id)
-          WHERE ((itemlocrsrv_source = 'SO')
-            AND  (itemlocrsrv_source_id = _r.shipitem_orderitem_id )
+          SELECT reserve_id INTO _reserveid
+          FROM reserve JOIN itemloc ON (reserve_supply_id=itemloc_id)
+          WHERE ((reserve_supply_type='I')
+            AND  (reserve_demand_type = 'SO')
+            AND  (reserve_demand_id = _r.shipitem_orderitem_id )
             AND  (itemloc_itemsite_id=_rsrv.shipitemlocrsrv_itemsite_id)
             AND  (itemloc_location_id=_rsrv.shipitemlocrsrv_location_id)
             AND  (COALESCE(itemloc_ls_id, -1)=COALESCE(_rsrv.shipitemlocrsrv_ls_id, -1))
@@ -181,14 +182,14 @@ BEGIN
           GET DIAGNOSTICS _rows = ROW_COUNT;
           IF (_rows > 0 ) THEN  
             -- Update existing
-            UPDATE itemlocrsrv
-            SET itemlocrsrv_qty = (itemlocrsrv_qty + _rsrv.shipitemlocrsrv_qty)
-            WHERE (itemlocrsrv_id=_itemlocrsvrid);
+            UPDATE reserve
+            SET reserve_qty = (reserve_qty + _rsrv.shipitemlocrsrv_qty)
+            WHERE (reserve_id=_reserveid);
           ELSE
             -- Recreate record
-            INSERT INTO itemlocrsrv
-            SELECT nextval('itemlocrsrv_itemlocrsrv_id_seq'), 'SO', _r.shipitem_orderitem_id,
-                   itemloc_id, _rsrv.shipitemlocrsrv_qty
+            INSERT INTO reserve
+            SELECT nextval('reserve_reserve_id_seq'), 'SO', _r.shipitem_orderitem_id,
+                   'I', itemloc_id, _rsrv.shipitemlocrsrv_qty, 'R'
             FROM itemloc
             WHERE ((itemloc_itemsite_id=_rsrv.shipitemlocrsrv_itemsite_id)
               AND  (itemloc_location_id=_rsrv.shipitemlocrsrv_location_id)
index dbbb5cf..a11b545 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION returnWoMaterial(INTEGER, NUMERIC, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWomatlid ALIAS FOR $1;
@@ -16,7 +16,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION returnWoMaterial(INTEGER, INTEGER, TIMESTAMP WITH TIME ZONE, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWomatlid ALIAS FOR $1;
@@ -131,7 +131,7 @@ COMMENT ON FUNCTION returnwomaterial(integer, integer, timestamp with time zone,
 
 select dropIfExists('FUNCTION', 'returnWoMaterial(INTEGER, NUMERIC, INTEGER, TIMESTAMP WITH TIME ZONE)'); 
 CREATE OR REPLACE FUNCTION returnWoMaterial(INTEGER, NUMERIC, INTEGER, TIMESTAMP WITH TIME ZONE, BOOLEAN DEFAULT FALSE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWomatlid ALIAS FOR $1;
index 0d358d9..7c50459 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION returnWoMaterialBatch(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoid ALIAS FOR $1;
index 92dd13f..94698c9 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION reverseCashReceipt(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCashrcptid ALIAS FOR $1;
index e70ba88..fab6ace 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION reverseCashReceiptDisc(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCashrcptItemId ALIAS FOR $1;
index ab9b956..93e3acc 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION reverseGLSeries(INTEGER, DATE, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSequence ALIAS FOR $1;
index ff5ff64..dff06d4 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION revokeAllModuleCmnttypeSource(INTEGER, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCmnttypeid ALIAS FOR $1;
index 1ba7881..3597dc5 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION revokeAllModulePriv(TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pUsername ALIAS FOR $1;
index 89f3ebd..c6d723f 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION revokeAllModulePrivGroup(INTEGER, TEXT) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pGrpid ALIAS FOR $1;
index bc8a01a..52c4cbd 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION revokeCmnttypeSource(INTEGER, INTEGER) RETURNS BOOL AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCmnttypeid ALIAS FOR $1;
index 05860b3..252563a 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION revokeGroup(TEXT, INTEGER) RETURNS BOOL AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pUsername ALIAS FOR $1;
index a77d9c6..121a626 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION revokePriv(TEXT, INTEGER) RETURNS BOOL AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pUsername ALIAS FOR $1;
@@ -21,7 +21,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION revokePriv(TEXT, TEXT) RETURNS BOOL AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pUsername ALIAS FOR $1;
index a8058ca..2c7e707 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION revokePrivGroup(INTEGER, INTEGER) RETURNS BOOL AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pGrpid ALIAS FOR $1;
index 54fb0f2..bca71cd 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION rollUpActualCost(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
     pItemid ALIAS FOR $1;
index 6705b5b..7c3a03d 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION rollUpSorACost(INTEGER, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid      ALIAS FOR $1;
index c1964a2..e8728b6 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION rollUpStandardCost(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
     pItemid ALIAS FOR $1;
index 6f7bdb6..fdba4de 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION roundCost(pCost NUMERIC) RETURNS NUMERIC IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _scale INTEGER;
index 15a8cce..aed50f1 100644 (file)
@@ -2,7 +2,7 @@
 CREATE OR REPLACE FUNCTION roundLocale(pFractional BOOLEAN,
                                        pQty NUMERIC,
                                        pLocale TEXT) RETURNS NUMERIC IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _r RECORD;
index bc1e318..aaf3711 100644 (file)
@@ -1,7 +1,7 @@
 
 CREATE OR REPLACE FUNCTION roundQty(pFractional BOOLEAN,
                                     pQty NUMERIC) RETURNS NUMERIC IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _scale INTEGER;
index b3a251d..5fe0de6 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION roundSale(pSale NUMERIC) RETURNS NUMERIC IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _scale INTEGER;
index 7a39e93..5d91c5d 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION roundUp(NUMERIC) RETURNS NUMERIC IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
 
index bdd0f06..d1bd5e9 100644 (file)
@@ -1,6 +1,6 @@
 CREATE OR REPLACE FUNCTION saveAddr(int4, text, text, text, text, text, text, text, text, boolean, text, text)
   RETURNS integer AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pAddrId ALIAS FOR $1;
@@ -152,7 +152,7 @@ $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION saveAddr(int4, text, text, text, text, text, text, text, text, text)
   RETURNS integer AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pAddrId ALIAS FOR $1;
index 7bf7de0..53690fe 100644 (file)
@@ -1,7 +1,7 @@
 SELECT dropIfExists('FUNCTION', 'saveAlarm(int,text,text,timestamp,int,text,text,text,int,text)', 'public');
 
 CREATE OR REPLACE FUNCTION saveAlarm(int,text,date,time,int,text,boolean,text,boolean,text,boolean,text,text,int,text) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pAlarmId ALIAS FOR $1;
index 8890c9e..1f51885 100644 (file)
@@ -1,6 +1,6 @@
 CREATE OR REPLACE FUNCTION saveBomHead(integer,text,date,text,numeric,numeric)
   RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index 11abaa5..2b9192c 100644 (file)
@@ -18,7 +18,7 @@ CREATE OR REPLACE FUNCTION saveCntct( pCntctId         INTEGER,
                                       pTitle           TEXT,
                                       pFlag            TEXT,
                                       pOwnerUsername   TEXT ) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _cntctId INTEGER;
@@ -162,7 +162,7 @@ CREATE OR REPLACE FUNCTION saveCntct( pCntctId         INTEGER,
                                       pNotes           TEXT,
                                       pTitle           TEXT,
                                       pFlag            TEXT ) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _returnVal INTEGER;
@@ -191,7 +191,7 @@ CREATE OR REPLACE FUNCTION saveCntct( pCntctId         INTEGER,
                                       pWebAddr         TEXT,
                                       pTitle           TEXT,
                                       pFlag            TEXT ) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _returnVal INTEGER;
index d54297b..ffe1569 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION saveImageAss(TEXT, INTEGER, CHAR, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSource      ALIAS FOR $1;
index 1c7890f..c572f38 100644 (file)
@@ -8,7 +8,7 @@ CREATE OR REPLACE FUNCTION saveIpsItem(pIpsItemId INTEGER,
                                        pPercent NUMERIC,
                                        pFixedAmt NUMERIC,
                                        pType TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _ipsitemid   INTEGER;
index 1019076..17f445b 100644 (file)
@@ -5,7 +5,7 @@ CREATE OR REPLACE FUNCTION saveIpsProdcat(pIpsProdcatId INTEGER,
                                           pDiscount NUMERIC,
                                           pFixedAmtDiscount NUMERIC,
                                           pType TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _ipsitemid   INTEGER;
index fb882eb..f608e03 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION saveItemImage(INTEGER, CHAR, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index 85fccdf..d8c8a43 100644 (file)
@@ -1,6 +1,6 @@
 CREATE OR REPLACE FUNCTION saveItemUomConv(integer, integer, numeric, integer, numeric, boolean, integer[])
   RETURNS integer AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemId ALIAS FOR $1;
index d41eee7..a85c21d 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION saveMetasql(TEXT, TEXT, TEXT, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN saveMetasql($1, $2, $3, $4, true, NULL, 0);
@@ -7,7 +7,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION saveMetasql(TEXT,TEXT,TEXT,TEXT,BOOL) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN saveMetasql($1, $2, $3, $4, $5, NULL, 0);
@@ -15,7 +15,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION saveMetasql(TEXT,TEXT,TEXT,TEXT,BOOL,TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN saveMetasql($1, $2, $3, $4, $5, $6, 0);
@@ -23,7 +23,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION saveMetasql(TEXT,TEXT,TEXT,TEXT,BOOL,TEXT,INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pGroup       ALIAS FOR $1;
index c7a013a..9ec611a 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION scraps(TEXT) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTransType ALIAS FOR $1;
index 18c7372..a96854e 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION scrapWoMaterial(INTEGER, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN scrapWoMaterial($1, $2, CURRENT_TIMESTAMP);
@@ -8,7 +8,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION scrapWoMaterial(INTEGER, NUMERIC, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWomatlid    ALIAS FOR $1;
index eff9473..34cb293 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION selectBalanceForBilling(INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSoheadid ALIAS FOR $1;
index 5922273..b16a248 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION selectDiscountItemsForPayment(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVendid ALIAS FOR $1;
index c44433d..e11a29c 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION selectDueItemsForPayment(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pVendid ALIAS FOR $1;
index 7520223..1dfc63a 100644 (file)
@@ -1,7 +1,7 @@
 CREATE OR REPLACE FUNCTION selectforbilling(integer, numeric, boolean)
   RETURNS integer AS
 $BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSoitemid    ALIAS FOR $1;
@@ -32,7 +32,7 @@ $BODY$ LANGUAGE 'plpgsql' VOLATILE;
 CREATE OR REPLACE FUNCTION selectforbilling(integer, numeric, boolean, integer)
   RETURNS integer AS
 $BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSoitemid    ALIAS FOR $1;
index 2f902b9..0bea0bc 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION selectPayment(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pApopenid ALIAS FOR $1;
@@ -14,17 +14,7 @@ BEGIN
   SELECT apopen_amount, apopen_paid,
          apopen_doctype, apopen_docdate,
          apopen_curr_id,
-         apopen_amount - apopen_paid
-           - COALESCE((SELECT SUM(currToCurr(checkitem_curr_id,
-                                             apopen_curr_id,
-                                             checkitem_amount + checkitem_discount,
-                                             checkhead_checkdate))
-                         FROM checkitem, checkhead
-                        WHERE((checkitem_checkhead_id=checkhead_id)
-                          AND (checkitem_apopen_id=apopen_id)
-                          AND (NOT checkhead_deleted)
-                          AND (NOT checkhead_replaced)
-                          AND (NOT checkhead_posted)) ),0) AS balance,
+         apopen_amount - apopen_paid - apCheckPending(apopen_id) AS balance,
          noNeg(COALESCE(apopen_discountable_amount, 0) *
                CASE WHEN (CURRENT_DATE <= determineDiscountDate(apopen_terms_id, apopen_docdate)) THEN terms_discprcnt
                     ELSE 0.0 END - discount_applied) AS discount_available
@@ -36,7 +26,7 @@ BEGIN
              AND (apapply_source_apopen_id=apopen_id)
              AND (apopen_discount)) ) AS data
    WHERE(apopen_id=pApopenid);
-  IF(NOT FOUND OR (NOT _p.apopen_doctype IN ('V','D'))) THEN
+  IF(NOT FOUND OR (NOT _p.apopen_doctype IN ('V','D','C'))) THEN
     RETURN -1;
   END IF;
 
index 3cead58..60c5cc6 100644 (file)
@@ -1,6 +1,6 @@
 CREATE OR REPLACE FUNCTION selectuninvoicedshipment(INTEGER) RETURNS INTEGER AS
 $BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pShipheadid ALIAS FOR $1;
index 4fe979b..f321f68 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION selectUninvoicedShipments(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWarehousid ALIAS FOR $1;
@@ -37,7 +37,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION selectUninvoicedShipments(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWarehousid ALIAS FOR $1;
@@ -79,7 +79,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION selectUninvoicedShipments(INTEGER, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWarehousid ALIAS FOR $1;
index ec989ea..9a48074 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION setApJournalNumber() RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _journalNumber INTEGER;
index 7e49e8f..4077291 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION setArJournalNumber() RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _journalNumber INTEGER;
index 6c207ea..854a2ea 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION setBudget(INTEGER, INTEGER, NUMERIC) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPeriodid ALIAS FOR $1;
@@ -13,7 +13,7 @@ END;
 ' LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION setBudget(INTEGER, INTEGER, INTEGER, NUMERIC) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pBudgheadid ALIAS FOR $1;
index 05cecac..fa2c6bc 100644 (file)
@@ -1,7 +1,7 @@
 CREATE OR REPLACE FUNCTION setbytea(text)
   RETURNS bytea AS
 '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pMetricName ALIAS FOR $1;
@@ -21,7 +21,7 @@ END;
 CREATE OR REPLACE FUNCTION setbytea(bytea)
   RETURNS bytea AS
 '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pMetricName ALIAS FOR $1;
index 133f30c..8e189ba 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION setCCBankAccnt(TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pccardtype   ALIAS FOR $1;
index 323c7b1..bb8bdd2 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION setEffectiveXtUser(TEXT) RETURNS BOOL AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pUsername ALIAS FOR $1;
index f36e6a1..4d3bc39 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION setGlJournalNumber(DATE, DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pStartDate ALIAS FOR $1;
index e6510c9..9af7b71 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION setMetric(TEXT, TEXT) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pMetricName ALIAS FOR $1;
index e0b9ae7..c802d9f 100644 (file)
@@ -1,7 +1,7 @@
 CREATE OR REPLACE FUNCTION setmetricenc(text, text, text)
   RETURNS bool AS
 '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pMetricName ALIAS FOR $1;
index 06dc9fb..0317a16 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION setNextAPMemoNumber(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pNumber ALIAS FOR $1;
index e828112..30b8c5e 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION setNextARMemoNumber(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pNumber ALIAS FOR $1;
index ffd347b..2a27e15 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION setNextCashRcptNumber(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pNumber ALIAS FOR $1;
index 19cd93c..a04b21a 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION setNextCheckNumber(INTEGER, INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pBankaccntid ALIAS FOR $1;
index a6b72dc..3168240 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION setNextCmNumber(INTEGER) RETURNS INTEGER  AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pNumber ALIAS FOR $1;
index 1c64f27..0abedc7 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION setNextCRMAccountNumber(INTEGER) RETURNS INTEGER  AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pNumber ALIAS FOR $1;
index 4caf308..3dd138c 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION setNextIncidentNumber(INTEGER) RETURNS INTEGER  AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pNumber ALIAS FOR $1;
index 794a115..dd21cbb 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION setNextInvcNumber(INTEGER) RETURNS INTEGER  AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pNumber ALIAS FOR $1;
index 09aa916..7382ff0 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION setNextNumber(TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   psequence    ALIAS FOR $1;
index e33d738..5e52db8 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION setNextPoNumber(INTEGER) RETURNS INTEGER  AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pNumber ALIAS FOR $1;
index b5ba0be..0061849 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION setNextPrNumber(INTEGER) RETURNS INTEGER  AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pNumber ALIAS FOR $1;
index 9b239a7..fb67690 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION setNextQuNumber(INTEGER) RETURNS INTEGER  AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pQuNumber ALIAS FOR $1;
index e679b6c..d630958 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION setNextShipmentNumber(INTEGER) RETURNS INTEGER  AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pShipmentNumber ALIAS FOR $1;
index 33337fc..a2ab38c 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION setNextSoNumber(INTEGER) RETURNS INTEGER  AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSoNumber ALIAS FOR $1;
index 364e1ba..e23cc7c 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION setNextVcNumber(INTEGER) RETURNS INTEGER  AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pNumber ALIAS FOR $1;
index d8a651f..5f0bfe1 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION setNextWoNumber(INTEGER) RETURNS INTEGER  AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pWoNumber ALIAS FOR $1;
index 3f83778..ca6e785 100644 (file)
@@ -1,6 +1,6 @@
 DROP FUNCTION IF EXISTS setuserCanCreateUsers(TEXT, BOOLEAN);
 CREATE OR REPLACE FUNCTION setuserCanCreateUsers(pUsername TEXT, pCreateUser BOOLEAN) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   IF (pCreateUser) THEN
index 2b82882..ada8f3b 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION setUserPreference(TEXT, TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPrefName ALIAS FOR $1;
@@ -12,7 +12,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION setUserPreference(TEXT, TEXT, TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pUsername ALIAS FOR $1;
index b4bb01f..23f7e23 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION shipments(TEXT) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTransType ALIAS FOR $1;
index 13b34e2..fffdc8e 100644 (file)
@@ -1,11 +1,11 @@
 CREATE OR REPLACE FUNCTION shipShipment(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
   SELECT shipShipment($1, CURRENT_TIMESTAMP);
 $$ LANGUAGE SQL;
 
 CREATE OR REPLACE FUNCTION shipShipment(INTEGER, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pshipheadid          ALIAS FOR $1;
@@ -271,7 +271,9 @@ BEGIN
 
       --We do not need to distribute lot/serial info for transit, post trans and discard dist detail
       PERFORM postIntoTrialBalance(itemlocpost_glseq) FROM itemlocpost WHERE (itemlocpost_itemlocseries=_itemlocSeries);
-      PERFORM postInvHist(_invhistid);
+      IF (_invhistid > 0) THEN
+        PERFORM postInvHist(_invhistid);
+      END IF;
       DELETE FROM itemlocdist WHERE (itemlocdist_series=_itemlocSeries);
       DELETE FROM itemlocpost WHERE (itemlocpost_itemlocSeries=_itemlocSeries);
 
@@ -295,7 +297,9 @@ BEGIN
         AND  (ti.itemsite_warehous_id=_to.tohead_trns_warehous_id));
       --We do not need to distribute lot/serial info for transit, post trans and discard dist detail
       PERFORM postIntoTrialBalance(itemlocpost_glseq) FROM itemlocpost WHERE (itemlocpost_itemlocseries=_itemlocSeries);
-      PERFORM postInvHist(_invhistid);
+      IF (_invhistid > 0) THEN
+        PERFORM postInvHist(_invhistid);
+      END IF;
       DELETE FROM itemlocdist WHERE (itemlocdist_series=_itemlocSeries);
       DELETE FROM itemlocpost WHERE (itemlocpost_itemlocSeries=_itemlocSeries);
 
index 486b7dd..020e972 100644 (file)
@@ -1,6 +1,6 @@
 CREATE OR REPLACE FUNCTION singleCharacteristicsToString(TEXT, INTEGER, TEXT, TEXT, INTEGER) RETURNS text AS
 $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTargetType ALIAS FOR $1;
index 8fce947..bb0ceb6 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION singlelevelBOM(INTEGER, INTEGER, INTEGER, INTEGER) RETURNS SETOF bomdata AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index 2322183..1041ce6 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION site() RETURNS SETOF whsinfo AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _row whsinfo%ROWTYPE;
index d3ae7d9..26f76b9 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION snoozeMessage(INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pMsgid ALIAS FOR $1;
index c24601e..0b578be 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION spellAmount(NUMERIC) RETURNS TEXT AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN spellAmount($1, baseCurrId());
@@ -8,7 +8,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION spellAmount(NUMERIC, INTEGER) RETURNS text AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pN ALIAS FOR $1;
index fc1842d..c059292 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION splitReceipt(INTEGER, NUMERIC, NUMERIC) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   precvid      ALIAS FOR $1;
index e799104..7d0ac4f 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION splitRecurrence(INTEGER, TEXT, TIMESTAMP WITH TIME ZONE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pParentid     ALIAS FOR $1;
index f759024..1d0d3e6 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION startoftime() RETURNS DATE IMMUTABLE AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 SELECT DATE('1970-01-01') AS return;
 $$ LANGUAGE sql;
index 1795108..5f9e403 100644 (file)
@@ -1,13 +1,13 @@
-CREATE OR REPLACE FUNCTION stdCost(INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION stdCost(INTEGER) RETURNS NUMERIC STABLE AS '
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN stdCost($1, NULL);
 END;
 ' LANGUAGE 'plpgsql';
 
-CREATE OR REPLACE FUNCTION stdCost(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+CREATE OR REPLACE FUNCTION stdCost(INTEGER, INTEGER) RETURNS NUMERIC STABLE AS '
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index 35f0927..5bf833a 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION sufficientInventoryToShipItem(TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pordertype    ALIAS FOR $1;
@@ -11,14 +11,14 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION sufficientInventoryToShipItem(TEXT, INTEGER, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
-  pordertype           ALIAS FOR $1;
-  porderitemid         ALIAS FOR $2;
-  pqty                  ALIAS FOR $3;
-  _returnVal           INTEGER;
-  _isqtyavail          BOOLEAN;
+  pordertype           ALIAS FOR $1;
+  porderitemid         ALIAS FOR $2;
+  pqty                 ALIAS FOR $3;
+  _returnVal           INTEGER;
+  _isqtyavail          BOOLEAN;
 
 BEGIN
   IF (porderitemid IS NULL) THEN
@@ -32,6 +32,7 @@ BEGIN
           WHERE (coitem_id=porderitemid)) THEN
         RETURN 0;
       END IF;
+
       SELECT (((COALESCE(pqty, roundQty(item_fractional,
                      noNeg(coitem_qtyord - coitem_qtyshipped +
                            coitem_qtyreturned - qtyAtShipping(pordertype, coitem_id)
@@ -125,6 +126,23 @@ BEGIN
     RETURN -3;
   END IF;
 
+  IF (pordertype = 'SO') THEN
+    IF ( SELECT fetchMetricBool('RequireSOReservations') ) THEN
+      SELECT (COALESCE(pqty, coitem_qtyreserved) <= coitem_qtyreserved)
+        INTO _isqtyavail
+        FROM coitem, itemsite, item
+       WHERE ((coitem_itemsite_id=itemsite_id) 
+         AND (coitem_status <> 'X')
+         AND  (NOT ((item_type IN ('R','J')) OR (itemsite_controlmethod = 'N'))) 
+         AND (itemsite_item_id=item_id) 
+         AND (coitem_id=porderitemid));
+    END IF;
+  END IF;
+
+  IF (NOT _isqtyavail) THEN
+    RETURN -4;
+  END IF;
+
   RETURN 0;
 END;
 $$ LANGUAGE 'plpgsql';
index 97f2bb9..c1cd445 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION sufficientInventoryToShipOrder(TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pordertype   ALIAS FOR $1;
index 87809d9..6b94aa5 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION summarizedBOM(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
@@ -16,7 +16,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION summarizedBOM(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
@@ -77,7 +77,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION summarizedBOM(INTEGER, INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
@@ -95,7 +95,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION summarizedBOM(INTEGER, INTEGER, INTEGER, INTEGER) RETURNS SETOF bomdata AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index be70b05..7fc44fa 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION summarizeTransactions(INTEGER, DATE, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index 479423a..34cadeb 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION summDemand(INTEGER, DATE, DATE) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
@@ -26,7 +26,7 @@ END;
 
 
 CREATE OR REPLACE FUNCTION summDemand(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index fcad159..6c6fe5c 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION summProd(INTEGER, DATE, DATE) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
@@ -26,7 +26,7 @@ END;
 
 
 CREATE OR REPLACE FUNCTION summProd(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index 2e07772..04a3ff5 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION summTransA (INTEGER, DATE, DATE) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
@@ -26,7 +26,7 @@ END;
 
 
 CREATE OR REPLACE FUNCTION summTransA(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index defa51a..5ff812f 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION summTransC (INTEGER, DATE, DATE) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
@@ -26,7 +26,7 @@ END;
 
 
 CREATE OR REPLACE FUNCTION summTransC(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index 5161bfc..79b3c9e 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION summTransI (INTEGER, DATE, DATE) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
@@ -26,7 +26,7 @@ END;
 
 
 CREATE OR REPLACE FUNCTION summTransI(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index d2d6c76..b4de2ea 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION summTransR (INTEGER, DATE, DATE) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
@@ -26,7 +26,7 @@ END;
 
 
 CREATE OR REPLACE FUNCTION summTransR(INTEGER, INTEGER) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index ba7fb64..5ffc57c 100644 (file)
@@ -1,7 +1,7 @@
 CREATE OR REPLACE FUNCTION summTransS (pItemsiteid INTEGER,
                                        pStartDate DATE,
                                        pEndDate DATE) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _value NUMERIC;
@@ -29,7 +29,7 @@ $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION summTransS(pItemsiteid INTEGER,
                                       pCalitemid INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index 02951a5..d9f6994 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION summTransT (INTEGER, DATE, DATE) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
@@ -28,7 +28,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION summTransT(INTEGER, INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index b93be0b..f62d206 100644 (file)
@@ -2,7 +2,7 @@
 CREATE OR REPLACE FUNCTION taxassignments(integer, integer)
   RETURNS SETOF taxassign AS
 $BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTaxZoneId ALIAS FOR $1;
index 0ab3521..d8bcc92 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION thawAccountingPeriod(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pPeriodid ALIAS FOR $1;
index 86aa2cf..ad24fb9 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION thawItemSite(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index f22e462..7a731f5 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION todoitem() RETURNS SETOF todoitem AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _row todoitem%ROWTYPE;
index 398ced8..52d9438 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION todoItemMove(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   ptodoItemId ALIAS FOR $1;
index 96aecd7..a29a1e3 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION todoItemMoveDown(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   ptodoItemId ALIAS FOR $1;
index 8dd2d40..3090fcc 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION todoItemMoveUp(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   ptodoItemId ALIAS FOR $1;
index f37c15c..8627ad5 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION toggleBankrecCleared(INTEGER, TEXT, INTEGER, NUMERIC, NUMERIC) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pBankrecid ALIAS FOR $1;
index dec6c85..1fe5597 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION toggleBomitemCost(INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pBomitemid ALIAS FOR $1;
index 973a100..4e37dc3 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION toNumeric(TEXT, NUMERIC) RETURNS NUMERIC IMMUTABLE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pText ALIAS FOR $1;
index c6b2f92..200f291 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION transitWhs() RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _id  INTEGER;
index f0c408e..8edcb4b 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION transType(TEXT, INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTransType ALIAS FOR $1;
index 5902859..9a1c306 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION tryLock(integer, integer) RETURNS boolean AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pKey1 ALIAS FOR $1;
index 0216f92..0ba6dce 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION undomerge(TEXT, TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pSchema       ALIAS FOR $1;
diff --git a/foundation-database/public/functions/unreleasepurchaseorder.sql b/foundation-database/public/functions/unreleasepurchaseorder.sql
new file mode 100644 (file)
index 0000000..f5a585d
--- /dev/null
@@ -0,0 +1,35 @@
+CREATE OR REPLACE FUNCTION unreleasePurchaseOrder(pPoheadid INTEGER) RETURNS INTEGER AS $$
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
+-- See www.xtuple.com/CPAL for the full text of the software license.
+BEGIN
+
+  IF ( ( SELECT (COUNT(*) > 0)
+         FROM poitem
+         WHERE ( (poitem_pohead_id=pPoheadid)
+           AND   ( (poitem_status='C') OR
+                   (poitem_qty_received > 0.0) OR
+                   (poitem_qty_returned > 0.0) OR
+                   (poitem_qty_vouchered > 0.0) ) ) ) ) THEN
+    RETURN -1;
+  END IF;
+
+  IF ( ( SELECT (pohead_status='O')
+         FROM pohead
+         WHERE (pohead_id=pPoheadid) ) ) THEN
+
+    --update status and erase the date that the order was released on
+    UPDATE pohead
+    SET pohead_status='U', pohead_released = NULL
+    WHERE (pohead_id=pPoheadid);
+
+  END IF;
+
+  --update status and erase the duedates at release
+  UPDATE poitem
+  SET poitem_status='U', poitem_rlsd_duedate = NULL
+  WHERE (poitem_pohead_id=pPoheadid);
+
+  RETURN 1;
+
+END;
+$$ LANGUAGE 'plpgsql';
index c11d207..c4f18dd 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION uomusedforitem(INTEGER) RETURNS SETOF uom AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pitemid       ALIAS FOR $1;
index d14404c..51f2f78 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION updateABCClass(TEXT, NUMERIC, NUMERIC, DATE, DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pClassCodePattern ALIAS FOR $1;
@@ -19,7 +19,7 @@ END;
 
 
 CREATE OR REPLACE FUNCTION updateABCClass(TEXT, INTEGER, NUMERIC, NUMERIC, DATE, DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pClassCodePattern ALIAS FOR $1;
@@ -127,7 +127,7 @@ END;
 
 
 CREATE OR REPLACE FUNCTION updateABCClass(INTEGER, NUMERIC, NUMERIC, DATE, DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pClasscodeid ALIAS FOR $1;
@@ -147,7 +147,7 @@ END;
 
 
 CREATE OR REPLACE FUNCTION updateABCClass(INTEGER, INTEGER, NUMERIC, NUMERIC, DATE, DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pClasscodeid ALIAS FOR $1;
index 1fc3f61..97c62b1 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION updateCharAssignment(TEXT, INTEGER, INTEGER, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTargetType ALIAS FOR $1;
@@ -18,7 +18,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION updateCharAssignment(TEXT, INTEGER, INTEGER, TEXT, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pTargetType ALIAS FOR $1;
index dc962c4..138e876 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION updateCost(INTEGER, NUMERIC) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemcostid ALIAS FOR $1;
@@ -11,7 +11,7 @@ END;
 ' LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION updateCost(INTEGER, NUMERIC, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
     pItemcostid ALIAS FOR $1;
@@ -42,7 +42,7 @@ END;
 
 
 CREATE OR REPLACE FUNCTION updateCost(INTEGER, TEXT, BOOLEAN, NUMERIC) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   returnVal INTEGER;
@@ -55,7 +55,7 @@ END;
 
 
 CREATE OR REPLACE FUNCTION updateCost(INTEGER, INTEGER, BOOLEAN, NUMERIC) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   returnVal INTEGER;
@@ -67,7 +67,7 @@ END;
 ' LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION updateCost(INTEGER, TEXT, BOOLEAN, NUMERIC, INTEGER) RETURNS integer AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
@@ -141,7 +141,7 @@ END;
 
 
 CREATE OR REPLACE FUNCTION updateCost(INTEGER, INTEGER, BOOLEAN, NUMERIC, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index 554727d..153ba88 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION updateCustomPrivs() RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _r RECORD;
index 0d2f7f8..b3f31a3 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION UpdateItemCost(INTEGER, INTEGER, INTEGER, NUMERIC, BOOLEAN) RETURNS INTEGER AS $BODY$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
 pItemId ALIAS FOR $1;
index 8f81f3b..548fb9b 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION updateItemSiteLeadTime(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index bd33cbc..f9027b9 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION updateListPrice(INTEGER, NUMERIC) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
index b598867..1b77696 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION updateLowerUserCosts(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid ALIAS FOR $1;
@@ -10,7 +10,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION updateLowerUserCosts(INTEGER, BOOLEAN) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid      ALIAS FOR $1;
index d0d5ce4..e0872e4 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION updateLowlevel(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
 
index cfbe42d..3681a9a 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION updateOUTLevel(INTEGER, INTEGER, INTEGER[]) RETURNS boolean AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index cccc602..1407624 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION updateReorderLevel(INTEGER, INTEGER, INTEGER[]) RETURNS boolean AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
@@ -11,7 +11,7 @@ DECLARE
   _usage NUMERIC;
   _totalUsage NUMERIC;
   _totalDays INTEGER;
-  _reorderLevel NUMERIC;
+  _reorderLevel INTEGER;
   _averageUsage NUMERIC;
   _result      TEXT;
 
@@ -66,7 +66,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION updateReorderLevel(INTEGER[], INTEGER, BOOLEAN, INTEGER[]) RETURNS SETOF reordlvl AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteids                 ALIAS FOR $1;
@@ -77,7 +77,7 @@ DECLARE
   _pcursor             INTEGER := 1;
   _totalUsage          NUMERIC := 0;
   _totalDays           INTEGER := 0;
-  _reorderLevel        NUMERIC := 0;
+  _reorderLevel        INTEGER := 0;
   _result              TEXT;
   _usage               NUMERIC;
   _averageUsage        NUMERIC;
index 1577612..ddbae50 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION updateRetainedEarnings(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pYearPeriodid ALIAS FOR $1;
index 9636f02..06014f6 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION updateSorACost(INTEGER, TEXT, BOOLEAN, NUMERIC, BOOLEAN) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemid      ALIAS FOR $1;
index 20b4e1a..1beee66 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION updateStdCost(INTEGER, NUMERIC, NUMERIC, TEXT, TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
     pItemcostid        ALIAS FOR $1;
@@ -97,7 +97,7 @@ $$ LANGUAGE 'plpgsql';
 
 
 CREATE OR REPLACE FUNCTION updateStdCost(INTEGER, TEXT, BOOLEAN, NUMERIC) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
     pItemid    ALIAS FOR $1;
index 85c2643..057dd5e 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION updateTodoItem(INTEGER, TEXT, TEXT, TEXT, INTEGER, INTEGER, INTEGER, DATE, DATE, CHARACTER(1), DATE, DATE, INTEGER, TEXT, BOOLEAN, TEXT) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN updateTodoItem($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, NULL);
@@ -8,7 +8,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION updateTodoItem(INTEGER, TEXT, TEXT, TEXT, INTEGER, INTEGER, INTEGER, DATE, DATE, CHARACTER(1), DATE, DATE, INTEGER, TEXT, BOOLEAN, TEXT, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   ptodoitemid ALIAS FOR  $1;
index ecc5708..a00509d 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION useDefaultLocation(INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index 625a375..f4e46c1 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION userCanCreateUsers(TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 SELECT rolcreaterole OR rolsuper
   FROM pg_roles
index a989560..72a559f 100644 (file)
@@ -1,7 +1,7 @@
 DROP VIEW     IF EXISTS usr;
 DROP FUNCTION IF EXISTS userCanLogin(TEXT);
 CREATE OR REPLACE FUNCTION userCanLogin(pUsername TEXT) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _isactive  BOOLEAN;
index 9e7957c..60c1dd8 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION userId(TEXT) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pUsername ALIAS FOR $1;
index 82de3c7..61cba7c 100644 (file)
@@ -1,6 +1,6 @@
 
 CREATE OR REPLACE FUNCTION validateOrderQty(INTEGER, NUMERIC, BOOLEAN) RETURNS NUMERIC AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pItemsiteid ALIAS FOR $1;
index 2a592a5..e728c07 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION validLocation(INTEGER, INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pLocationid ALIAS FOR $1;
@@ -46,7 +46,7 @@ END;
 -- testing.
 -- TODO: uncomment the following and test it. if it works, drop the one above
 -- CREATE OR REPLACE FUNCTION validLocation(INTEGER, INTEGER) RETURNS BOOLEAN AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 -- DECLARE
 --   pLocationid ALIAS FOR $1;
index 0727733..ece683a 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION valueAtShipping(plineitemid INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RETURN valueAtShipping('SO', plineitemid);
@@ -8,7 +8,7 @@ $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION valueAtShipping(pordertype TEXT,
                                            plineitemid INTEGER) RETURNS NUMERIC AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _value NUMERIC := 0.0;
index 6d33c0b..d0c9bd3 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION voidAPCheck(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RAISE NOTICE ''voidAPCheck() is deprecated - use voidCheck() instead'';
index 49984b2..bbbdbf4 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION voidApopenVoucher(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pApopenid ALIAS FOR $1;
@@ -9,7 +9,7 @@ END;
 $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION voidApopenVoucher(INTEGER, INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pApopenid ALIAS FOR $1;
@@ -298,7 +298,7 @@ BEGIN
     apopen_amount, apopen_paid, apopen_open, apopen_notes, apopen_discount, apopen_curr_rate )
   SELECT _apopenid, getEffectiveXtUser(), pJournalnumber,
          apopen_vend_id, apopen_docnumber, 'C', apopen_ponumber,
-         CURRENT_DATE, CURRENT_DATE, CURRENT_DATE, -1, apopen_curr_id,
+         _glDate, _glDate, _glDate, -1, apopen_curr_id,
          apopen_amount - apopen_paid, 0, TRUE, _reference, TRUE, apopen_curr_rate
     FROM apopen
    WHERE (apopen_id=_n.apopen_id);
index 4217fea..29ea330 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION voidCheck(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCheckid ALIAS FOR $1;
index 7669aed..b7a196b 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION voidCreditMemo(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCmheadid ALIAS FOR $1;
index a793d33..310f294 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION voidInvoice(INTEGER) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pInvcheadid ALIAS FOR $1;
@@ -31,7 +31,7 @@ BEGIN
   SELECT invchead.*,
          findFreightAccount(invchead_cust_id) AS freightaccntid,
          findARAccount(invchead_cust_id) AS araccntid,
-         aropen_id,
+         aropen_id, cohist_unitcost,
          ( SELECT COALESCE(SUM(taxhist_tax), 0)
            FROM invcheadtax
            WHERE ( (taxhist_parent_id = invchead_id)
@@ -42,6 +42,7 @@ BEGIN
              AND   (taxhist_taxtype_id = getAdjustmentTaxtypeId()) ) ) AS adjtax
        INTO _p 
   FROM invchead JOIN aropen ON (aropen_doctype='I' AND aropen_docnumber=invchead_invcnumber)
+                JOIN cohist ON (cohist_doctype='I' AND cohist_invcnumber=invchead_invcnumber)
   WHERE (invchead_id=pInvcheadid);
   IF (NOT FOUND) THEN
     RAISE EXCEPTION 'Cannot Void Invoice as invchead not found';
@@ -326,7 +327,7 @@ BEGIN
                           JOIN item ON (item_id=invcitem_item_id)
             WHERE (invchead_id=_p.invchead_id) LOOP
 
---  Issue billed stock from inventory
+--  Return billed stock to inventory
     IF (_itemlocSeries = 0) THEN
       SELECT NEXTVAL('itemloc_series_seq') INTO _itemlocSeries;
     END IF;
@@ -334,10 +335,10 @@ BEGIN
                          'S/O', 'IN', _r.invchead_invcnumber, '',
                          ('Invoice Voided ' || _r.item_number),
                          getPrjAccntId(_r.prj_id, resolveCOSAccount(itemsite_id, _r.cust_id, _r.saletype_id, _r.shipzone_id)),
-                         costcat_asset_accnt_id, _itemlocSeries, _glDate) INTO _invhistid
-    FROM itemsite, costcat
-    WHERE ( (itemsite_costcat_id=costcat_id)
-     AND (itemsite_id=_r.itemsite_id) );
+                         costcat_asset_accnt_id, _itemlocSeries, _glDate,
+                         (_p.cohist_unitcost * _r.qty)) INTO _invhistid
+    FROM itemsite JOIN costcat ON (itemsite_costcat_id=costcat_id)
+    WHERE (itemsite_id=_r.itemsite_id);
 
   END LOOP;
 
index 6b8ec1a..4b8b17d 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION voidPostedAPCheck(INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RAISE NOTICE ''voidPostedAPCheck() is deprecated - use voidPostedCheck() instead'';
@@ -9,7 +9,7 @@ END;
 
 
 CREATE OR REPLACE FUNCTION voidPostedAPCheck(INTEGER, INTEGER) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RAISE NOTICE ''voidPostedAPCheck() is deprecated - use voidPostedCheck() instead'';
@@ -18,7 +18,7 @@ END;
 ' LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION voidPostedAPCheck(INTEGER, INTEGER, DATE) RETURNS INTEGER AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 BEGIN
   RAISE NOTICE ''voidPostedAPCheck() is deprecated - use voidPostedCheck() instead'';
index 6e5af58..55d33ca 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION voidPostedCheck(INTEGER, INTEGER, DATE) RETURNS INTEGER AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pCheckid             ALIAS FOR $1;
@@ -45,15 +45,18 @@ BEGIN
   SELECT trans_id INTO _result
   FROM ( SELECT gltrans_id AS trans_id
          FROM gltrans
-         WHERE ((gltrans_doctype='CK')
-           AND  (gltrans_misc_id=_p.checkhead_id)
-           AND  (gltrans_rec))
+              LEFT OUTER JOIN bankrecitem ON (bankrecitem_source='GL' AND bankrecitem_source_id=gltrans_id)
+         WHERE ( (gltrans_doctype='CK')
+           AND   (gltrans_misc_id=_p.checkhead_id)
+           AND   ((gltrans_rec) OR (bankrecitem_id IS NOT NULL)) )
          UNION ALL
          SELECT sltrans_id AS trans_id
          FROM sltrans
-         WHERE ((sltrans_doctype='CK')
-           AND  (sltrans_misc_id=_p.checkhead_id)
-           AND  (sltrans_rec)) ) AS data;
+              LEFT OUTER JOIN bankrecitem ON (bankrecitem_source='GL' AND bankrecitem_source_id=sltrans_id)
+         WHERE ( (sltrans_doctype='CK')
+           AND   (sltrans_misc_id=_p.checkhead_id)
+           AND   ((sltrans_rec) OR (bankrecitem_id IS NOT NULL)) )
+       ) AS data;
   IF (FOUND) THEN
     RETURN -14;
   END IF;
@@ -109,14 +112,20 @@ BEGIN
 
   ELSE
     FOR _r IN SELECT checkitem_amount, checkitem_discount,
-                     CASE WHEN (checkitem_apopen_id IS NOT NULL) THEN
-                       checkitem_amount / apopen_curr_rate
-                     ELSE
-                       currToBase(checkitem_curr_id,
-                                  checkitem_amount,
-                                  COALESCE(checkitem_docdate, _p.checkhead_checkdate)) 
+                     CASE WHEN (checkitem_apopen_id IS NOT NULL AND apopen_doctype='C') THEN
+                            checkitem_amount / apopen_curr_rate * -1.0
+                          WHEN (checkitem_apopen_id IS NOT NULL) THEN
+                            checkitem_amount / apopen_curr_rate
+                          ELSE
+                            currToBase(checkitem_curr_id,
+                                       checkitem_amount,
+                                       COALESCE(checkitem_docdate, _p.checkhead_checkdate)) 
                      END AS checkitem_amount_base,
-                       checkitem_amount / checkitem_curr_rate   AS amount_check,
+                     currTocurr(checkitem_curr_id, _p.checkhead_curr_id,
+                                CASE WHEN (checkitem_apopen_id IS NOT NULL AND apopen_doctype='C') THEN
+                                          checkitem_amount * -1.0
+                                     ELSE checkitem_amount END,
+                                  _p.checkhead_checkdate) AS amount_check,
                      apopen_id, apopen_doctype, apopen_docnumber, apopen_curr_rate, apopen_docdate,
                      aropen_id, aropen_doctype, aropen_docnumber,
                      checkitem_curr_id, checkitem_curr_rate,
@@ -152,13 +161,13 @@ BEGIN
 
 
           PERFORM insertIntoGLSeries( _sequence, _p.checkrecip_gltrans_source,
-                                     'DS', _r.apopen_docnumber,
+                                      'DS', _r.apopen_docnumber,
                                       findAPDiscountAccount(_p.checkhead_recip_id),
                                       round(_r.checkitem_discount / _r.apopen_curr_rate, 2) * -1,
                                       pVoidDate, _gltransNote, pCheckid);
 
           PERFORM insertIntoGLSeries( _sequence, _p.checkrecip_gltrans_source,
-                                     'DS', _r.apopen_docnumber,
+                                      'DS', _r.apopen_docnumber,
                                       findAPAccount(_p.checkhead_recip_id),
                                       round(_r.checkitem_discount / _r.apopen_curr_rate, 2),
                                       pVoidDate, _gltransNote, pCheckid);
@@ -231,11 +240,13 @@ BEGIN
           END IF;
         ELSE
           -- unusual condition where bank overridden and different currency from voucher
-          IF (_r.apopen_docdate > _p.checkhead_checkdate) THEN
-            _exchGainTmp := ((_r.checkitem_amount/_r.checkitem_curr_rate) - (_r.checkitem_amount / _r.apopen_curr_rate)) * -1;
-          ELSE
-            _exchGainTmp := ((_r.checkitem_amount / _r.apopen_curr_rate) - (_r.checkitem_amount/_r.checkitem_curr_rate));
-          END IF;
+          -- this does not work for all situations
+          --IF (_r.apopen_docdate > _p.checkhead_checkdate) THEN
+          --  _exchGainTmp := ((_r.checkitem_amount/_r.checkitem_curr_rate) - (_r.checkitem_amount / _r.apopen_curr_rate)) * -1;
+          --ELSE
+          --  _exchGainTmp := ((_r.checkitem_amount / _r.apopen_curr_rate) - (_r.checkitem_amount/_r.checkitem_curr_rate));
+          --END IF;
+          _exchGainTmp := 0.0;
         END IF;
       ELSE
         SELECT arCurrGain(_r.aropen_id,_r.checkitem_curr_id, _r.checkitem_amount,
index 880efd3..a5496ed 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION woEffectiveDate(DATE) RETURNS DATE AS '
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   pStartDate ALIAS FOR $1;
index 4ef05f1..4e83408 100644 (file)
@@ -1,7 +1,7 @@
 
 CREATE OR REPLACE FUNCTION woinvavail(integer, boolean, boolean, boolean, boolean)
   RETURNS SETOF woinvav AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
    pwoid ALIAS FOR $1;   
@@ -162,7 +162,7 @@ $$ LANGUAGE 'plpgsql';
 
 CREATE OR REPLACE FUNCTION woinvavail(integer, integer, boolean, boolean)
   RETURNS SETOF woinvav AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
    pwoid ALIAS FOR $1; 
index c94d0f2..b2691c0 100644 (file)
@@ -1,6 +1,6 @@
 CREATE OR REPLACE FUNCTION woinvavailmatl(integer, integer, boolean, boolean)
   RETURNS SETOF woinvav AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
    pwoid ALIAS FOR $1;    
index cad4178..cf6d41a 100644 (file)
@@ -1,5 +1,5 @@
 CREATE OR REPLACE FUNCTION wostarted(pWoid INTEGER) RETURNS BOOLEAN AS $$
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple. 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
 -- See www.xtuple.com/CPAL for the full text of the software license.
 DECLARE
   _result BOOLEAN := FALSE;
index 195a59a..6565d96 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: accountNumbers
 -- Name: detail
 -- Notes: used by accountNumbers
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT accnt_id, *,
index 753d9c6..ffcf7ef 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: addresses
 -- Name:  detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT DISTINCT ON (addr_country, addr_state, addr_city, addr_line1, addr_number) 
index 518d7b3..2c6ea41 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: allocations
 -- Name: detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT source_id, type, order_number, item_number, totalqty, relievedqty, balanceqty, duedate,
index f06790e..76bc311 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: apAging
 -- Name: detail
 -- Notes: used by dspTimePhasedOpenAPItems
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT apaging_vend_id, apaging_vend_number, apaging_vend_name,
index 78f8470..d0054f5 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: apApplications
 -- Name: detail
 -- Notes: used by dspAPApplications
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT apapply.*,
index f64a25a..77c43bc 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: apOpenItems
 -- Name:  detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT apopen_id, apopen_ponumber, apopen_docnumber,
index c4b2da3..f31552f 100644 (file)
@@ -1,29 +1,62 @@
 -- Group: apOpenItems
 -- Name:  selectedpayments
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
-SELECT apopen_id, apselect_id,
-       (bankaccnt_name || '-' || bankaccnt_descrip) AS f_bank,
-       (vend_number || '-' || vend_name) AS f_vendor,
+SELECT *,
        CASE WHEN (apopen_doctype='V') THEN <? value("voucher") ?>
             WHEN (apopen_doctype='D') THEN <? value("debitmemo") ?>
+            WHEN (apopen_doctype='C') THEN <? value("creditmemo") ?>
        END AS doctype,
-       apopen_docnumber, apopen_ponumber, apselect_amount,
-       apopen_invcnumber,
-       currToBase(apselect_curr_id, apselect_amount, CURRENT_DATE) AS apselect_amount_base,
-       currToBase(apselect_curr_id, apselect_amount, CURRENT_DATE) AS apselect_running_base,
-       currConcat(apselect_curr_id) AS currAbbr,
        'curr' AS apselect_amount_xtnumericrole,
        'curr' AS apselect_amount_base_xtnumericrole,
        'curr' AS apselect_running_base_xtnumericrole,
        0 AS apselect_running_base_xtrunninginit,
        1 AS apselect_running_base_xtrunningrole
+FROM (
+-- Vouchers and Debits
+SELECT apopen_id, apselect_id,
+       (bankaccnt_name || '-' || bankaccnt_descrip) AS f_bank,
+       (vend_number || '-' || vend_name) AS f_vendor,
+       apopen_docnumber, apopen_ponumber, apselect_amount,
+       apopen_invcnumber, apopen_doctype,
+       currToBase(apselect_curr_id, apselect_amount, CURRENT_DATE) AS apselect_amount_base,
+       currToBase(apselect_curr_id, apselect_amount, CURRENT_DATE) AS apselect_running_base,
+       currConcat(apselect_curr_id) AS currAbbr
+FROM apopen, apselect, vendinfo, bankaccnt
+WHERE ( (apopen_vend_id=vend_id)
+  AND   (apselect_apopen_id=apopen_id)
+  AND   (apselect_bankaccnt_id=bankaccnt_id) 
+  AND   (apopen_doctype IN ('V', 'D'))
+<? if exists("bankaccntid") ?>
+  AND   (bankaccnt_id=<? value("bankaccntid") ?>)
+<? endif ?>
+<? if exists("vend_id") ?>
+  AND (vend_id=<? value("vend_id") ?>)
+<? elseif exists("vendtype_id") ?>
+  AND (vend_vendtype_id=<? value("vendtype_id") ?>)
+<? elseif exists("vendtype_pattern") ?>
+  AND (vend_vendtype_id IN (SELECT vendtype_id
+                            FROM vendtype
+                            WHERE (vendtype_code ~ <? value("vendtype_pattern") ?>)))
+<? endif ?>
+ )
+UNION
+-- Credits
+SELECT apopen_id, apselect_id,
+       (bankaccnt_name || '-' || bankaccnt_descrip) AS f_bank,
+       (vend_number || '-' || vend_name) AS f_vendor,
+       apopen_docnumber, apopen_ponumber, apselect_amount,
+       apopen_invcnumber, apopen_doctype,
+       currToBase(apselect_curr_id, apselect_amount, CURRENT_DATE) AS apselect_amount_base,
+       currToBase(apselect_curr_id, apselect_amount, CURRENT_DATE) * -1.0 AS apselect_running_base,
+       currConcat(apselect_curr_id) AS currAbbr
 FROM apopen, apselect, vendinfo, bankaccnt
 WHERE ( (apopen_vend_id=vend_id)
   AND   (apselect_apopen_id=apopen_id)
   AND   (apselect_bankaccnt_id=bankaccnt_id) 
+  AND   (apopen_doctype='C')
 <? if exists("bankaccntid") ?>
   AND   (bankaccnt_id=<? value("bankaccntid") ?>)
 <? endif ?>
@@ -37,4 +70,5 @@ WHERE ( (apopen_vend_id=vend_id)
                             WHERE (vendtype_code ~ <? value("vendtype_pattern") ?>)))
 <? endif ?>
  )
-ORDER BY bankaccnt_name, vend_number, apopen_docnumber;
+ORDER BY f_bank, f_vendor, apopen_docnumber
+) AS data;
index 8ee8b14..11d091c 100644 (file)
@@ -1,33 +1,19 @@
 -- Group: apOpenItems
 -- Name:  selectpayments
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
-SELECT * FROM (
-SELECT apopen_id, COALESCE(apselect_id, -1) AS apselectid,
-       (vend_number || '-' || vend_name) AS vendor,
+SELECT *,
        CASE WHEN (apopen_doctype='V') THEN <? value("voucher") ?>
-            When (apopen_doctype='D') THEN <? value("debitMemo") ?>
+            WHEN (apopen_doctype='D') THEN <? value("debitMemo") ?>
+            WHEN (apopen_doctype='C') THEN <? value("creditMemo") ?>
        END AS doctype,
-       apopen_docnumber, apopen_ponumber,
-       apopen_duedate,
-       apopen_docdate, apopen_status,
-       CASE WHEN (apopen_status = 'H') THEN 'error' END AS qtforegroundrole,
-       (apopen_amount - apopen_paid - apCheckPending(apopen_id)) AS amount,
-       ((apopen_amount - apopen_paid - apCheckPending(apopen_id)) / apopen_curr_rate) AS base_amount,
-       ((apopen_amount - apopen_paid - apCheckPending(apopen_id)) / apopen_curr_rate) AS running_amount,
-       COALESCE(apselect_amount, 0.0) AS selected,
-       (COALESCE(apselect_amount, 0.0) / apopen_curr_rate) AS base_selected,
-       (COALESCE(apselect_amount, 0.0) / apopen_curr_rate) AS running_selected,
-       COALESCE(apselect_discount,0.0) AS discount,
-       (COALESCE(apselect_discount,0.0) / apopen_curr_rate)AS base_discount,
        CASE WHEN (apopen_duedate < CURRENT_DATE) THEN 'error'
             WHEN(apopen_duedate > CURRENT_DATE) THEN 'emphasis'
             WHEN(CURRENT_DATE <= determineDiscountDate(apopen_terms_id, apopen_docdate)) THEN 'altemphasis'
        END AS apopen_duedate_qtforegroundrole, 
-       apopen_invcnumber,
-       currConcat(apopen_curr_id) AS curr_concat,
+       CASE WHEN (apopen_status = 'H') THEN 'error' END AS qtforegroundrole,
        'curr' AS amount_xtnumericrole,
        'curr' AS selected_xtnumericrole,
        'curr' AS running_selected_xtnumericrole,
@@ -43,6 +29,21 @@ SELECT apopen_id, COALESCE(apselect_id, -1) AS apselectid,
        0      AS running_amount_xtrunninginit,
        1      AS running_selected_xtrunningrole,
        1      AS running_amount_xtrunningrole
+ FROM (
+-- Vouchers and Debits
+SELECT apopen_id, COALESCE(apselect_id, -1) AS apselectid,
+       (vend_number || '-' || vend_name) AS vendor,
+       apopen_doctype, apopen_docnumber, apopen_ponumber, apopen_invcnumber,
+       apopen_duedate, apopen_terms_id, apopen_docdate, apopen_status,
+       (apopen_amount - apopen_paid - apCheckPending(apopen_id)) AS amount,
+       ((apopen_amount - apopen_paid - apCheckPending(apopen_id)) / apopen_curr_rate) AS base_amount,
+       ((apopen_amount - apopen_paid - apCheckPending(apopen_id)) / apopen_curr_rate) AS running_amount,
+       COALESCE(apselect_amount, 0.0) AS selected,
+       (COALESCE(apselect_amount, 0.0) / apopen_curr_rate) AS base_selected,
+       (COALESCE(apselect_amount, 0.0) / apopen_curr_rate) AS running_selected,
+       COALESCE(apselect_discount,0.0) AS discount,
+       (COALESCE(apselect_discount,0.0) / apopen_curr_rate)AS base_discount,
+       currConcat(apopen_curr_id) AS curr_concat
 FROM vendinfo JOIN apopen ON (apopen_vend_id=vend_id)
               LEFT OUTER JOIN apselect ON (apselect_apopen_id=apopen_id)
 WHERE ( (apopen_open)
@@ -65,5 +66,42 @@ WHERE ( (apopen_open)
  AND (apopen_curr_id=<? value("curr_id") ?>)
 <? endif ?>
 )
-ORDER BY apopen_duedate, (apopen_amount - apopen_paid) DESC) AS data
+UNION
+-- Credits
+SELECT apopen_id, COALESCE(apselect_id, -1) AS apselectid,
+       (vend_number || '-' || vend_name) AS vendor,
+       apopen_doctype, apopen_docnumber, apopen_ponumber, apopen_invcnumber,
+       apopen_duedate, apopen_terms_id, apopen_docdate, apopen_status,
+       (apopen_amount - apopen_paid - apCheckPending(apopen_id)) AS amount,
+       ((apopen_amount - apopen_paid - apCheckPending(apopen_id)) / apopen_curr_rate) AS base_amount,
+       ((apopen_amount - apopen_paid - apCheckPending(apopen_id)) / apopen_curr_rate) * -1.0 AS running_amount,
+       COALESCE(apselect_amount, 0.0) AS selected,
+       (COALESCE(apselect_amount, 0.0) / apopen_curr_rate) AS base_selected,
+       (COALESCE(apselect_amount, 0.0) / apopen_curr_rate) * -1.0 AS running_selected,
+       COALESCE(apselect_discount,0.0) AS discount,
+       (COALESCE(apselect_discount,0.0) / apopen_curr_rate)AS base_discount,
+       currConcat(apopen_curr_id) AS curr_concat
+FROM vendinfo JOIN apopen ON (apopen_vend_id=vend_id)
+              LEFT OUTER JOIN apselect ON (apselect_apopen_id=apopen_id)
+WHERE ( (apopen_open)
+ AND (apopen_doctype = 'C')
+<? if exists("vend_id") ?>
+ AND (vend_id=<? value("vend_id") ?>)
+<? elseif exists("vendtype_id") ?>
+ AND (vend_vendtype_id=<? value("vendtype_id") ?>)
+<? elseif exists("vendtype_pattern") ?>
+ AND (vend_vendtype_id IN (SELECT vendtype_id
+                           FROM vendtype
+                           WHERE (vendtype_code ~ <? value("vendtype_pattern") ?>)))
+<? endif ?>
+<? if exists("olderDate") ?>
+ AND (apopen_duedate <= <? value("olderDate") ?>)
+<? elseif exists("startDate") ?>
+ AND (apopen_duedate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)
+<? endif ?>
+<? if exists("curr_id") ?>
+ AND (apopen_curr_id=<? value("curr_id") ?>)
+<? endif ?>
+)
+ORDER BY apopen_duedate, amount DESC) AS data
 WHERE (amount != 0);
index 4d67159..de15965 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: arAging
 -- Name: detail
 -- Notes: used by dspTimePhasedOpenARItems
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT araging_cust_id, araging_cust_number, araging_cust_name,
index 83fd2d8..e209910 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: arApplications
 -- Name: detail
 -- Notes: used by dspARApplications
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT arapply.*,
index 290fcf1..890a2e6 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: arHistory
 -- Name: detail
 -- Notes: used by dspCustomerARHistory, dspCustomerInformation
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT aropen_id, applyid,
index 56b963d..2abdcb7 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: arOpenApplications
 -- Name: detail
 -- Notes: used by applyARCreditMemo, cashReceipt
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT *,
@@ -40,16 +40,18 @@ FROM (SELECT
        (CASE WHEN aropen_doctype IN ('C','R') THEN -1 ELSE 1 END ) AS balance,
        aropen_curr_id AS balance_curr,
 <? if exists("cashrcpt_id") ?>
-       (SELECT COALESCE(SUM(p.cashrcptitem_amount), 0)
-                      FROM cashrcptitem p
-                     WHERE (p.cashrcptitem_aropen_id=aropen_id)
-                     AND (p.cashrcptitem_cashrcpt_id=<? value("cashrcpt_id") ?>))
-                   AS applied,
-       (SELECT COALESCE(SUM(p.cashrcptitem_discount), 0)
-                      FROM cashrcptitem p
-                     WHERE (p.cashrcptitem_aropen_id=aropen_id)
-                     AND (p.cashrcptitem_cashrcpt_id=<? value("cashrcpt_id") ?>))
-                   AS discount,
+       COALESCE(s.cashrcptitem_amount, 0.0) AS applied,
+       COALESCE(s.cashrcptitem_discount, 0.0) AS discount,
+--       (SELECT COALESCE(SUM(p.cashrcptitem_amount), 0)
+--                      FROM cashrcptitem p
+--                     WHERE (p.cashrcptitem_aropen_id=aropen_id)
+--                     AND (p.cashrcptitem_cashrcpt_id=<? value("cashrcpt_id") ?>))
+--                   AS applied,
+--       (SELECT COALESCE(SUM(p.cashrcptitem_discount), 0)
+--                      FROM cashrcptitem p
+--                     WHERE (p.cashrcptitem_aropen_id=aropen_id)
+--                     AND (p.cashrcptitem_cashrcpt_id=<? value("cashrcpt_id") ?>))
+--                   AS discount,
        currConcat(cashrcpt_curr_id) AS applied_curr,
 <? elseif exists("source_aropen_id") ?>
        COALESCE(arcreditapply_amount, 0) AS applied,
index 7019a01..45199c6 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: arOpenItems
 -- Name: detail
 -- Notes: used by arWorkBench, dspAROpenItems
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 <? if exists("totalOnly") ?>
@@ -121,7 +121,7 @@ SELECT -1 AS id,
        NULL::date AS aropen_duedate,
        NULL::text AS ordernumber,
        -1 AS ordernumber_xtidrole,
-       <? value("creditMemo") ?>  AS doctype,
+       <? value("return") ?>  AS doctype,
        CASE WHEN (NOT cmhead_posted) THEN 'emphasis'
        END AS doctype_qtforegroundrole,
        creditmemototal(cmhead_id) AS amount,
index 0ec2c52..e523cab 100644 (file)
@@ -5,7 +5,7 @@
 --        display class.  Used to be printed version got an extra parameter. Formatted
 --        values slow things down considerably on screen version otherwise. This
 --        should go away if/when we get OpenRPT to do its own formatting.
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 <? if exists("totalOnly") ?>
@@ -123,7 +123,7 @@ SELECT -1 AS id,
        NULL::date AS aropen_duedate,
        NULL::text AS ordernumber,
        -1 AS ordernumber_xtidrole,
-       <? value("creditMemo") ?>  AS doctype,
+       <? value("return") ?>  AS doctype,
        CASE WHEN (NOT cmhead_posted) THEN 'emphasis'
        END AS doctype_qtforegroundrole,
        creditmemototal(cmhead_id) AS amount,
diff --git a/foundation-database/public/tables/metasql/assessFinanceCharges-detail.mql b/foundation-database/public/tables/metasql/assessFinanceCharges-detail.mql
new file mode 100644 (file)
index 0000000..94c8e04
--- /dev/null
@@ -0,0 +1,51 @@
+-- Group: assessFinanceCharges
+-- Name:  detail
+-- Notes: 
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+
+SELECT aropen_id, aropen_docnumber, aropen_duedate, aropen_docdate,
+       aropen_amount, aropen_paid, balance, aropen_fincharg_date, aropen_fincharg_amount,
+       cust_number, cust_name,
+       CASE WHEN (currToLocal(aropen_curr_id, fincharg_mincharg, aropen_distdate) >
+                  (CASE WHEN (fincharg_assessoverdue)
+                        THEN (balance + prevfincharge)
+                        ELSE balance END * fincharg_air / 100.0 / 365 * CASE WHEN (fincharg_calcfrom=1)
+                                                                             THEN duedateoverdue
+                                                                             ELSE docdateoverdue END))
+            THEN currToLocal(aropen_curr_id, fincharg_mincharg, aropen_distdate)
+            ELSE (CASE WHEN (fincharg_assessoverdue)
+                       THEN (balance + prevfincharge)
+                       ELSE balance END * fincharg_air / 100.0 / 365 * CASE WHEN (fincharg_calcfrom=1)
+                                                                            THEN duedateoverdue
+                                                                            ELSE docdateoverdue END)
+       END AS fincharge
+FROM fincharg,
+     (SELECT *,
+             (aropen_amount - aropen_paid) AS balance,
+             COALESCE(aropen_fincharg_amount, 0.0) AS prevfincharge,
+             (<? value("assessmentDate") ?> - COALESCE(aropen_fincharg_date, aropen_duedate)) AS duedateoverdue,
+             (<? value("assessmentDate") ?> - COALESCE(aropen_fincharg_date, aropen_docdate)) AS docdateoverdue
+      FROM aropen JOIN custinfo ON (cust_id=aropen_cust_id)
+                  LEFT OUTER JOIN terms ON (terms_id=aropen_terms_id)
+                  LEFT OUTER JOIN custtype ON (cust_custtype_id=custtype_id)
+                  LEFT OUTER JOIN custgrpitem ON (custgrpitem_cust_id=cust_id)
+      WHERE ((aropen_doctype='I')
+        AND  (aropen_open)
+        AND  (COALESCE(terms_fincharg, FALSE))
+        AND  (COALESCE(cust_financecharge, TRUE))
+      <? if exists("cust_id") ?>
+        AND   (aropen_cust_id=<? value("cust_id") ?>)
+      <? endif ?>
+      <? if exists("custtype_id") ?>
+        AND   (custtype_id=<? value("custtype_id") ?>)
+      <? endif ?>
+      <? if exists("custtype_pattern") ?>
+        AND   (custtype_code~<? value("custtype_pattern") ?>)
+      <? endif ?>
+      <? if exists("custgrp_id") ?>
+        AND   (custgrpitem_custgrp_id=<? value("custgrp_id") ?>)
+      <? endif ?>
+      )) AS data
+WHERE ((COALESCE(aropen_fincharg_date, aropen_duedate) + COALESCE(cust_gracedays, fincharg_graceperiod)) < <? value("assessmentDate") ?>)
+ORDER BY cust_number, aropen_docnumber;
index 17e2ee2..0e5afef 100644 (file)
@@ -2,7 +2,7 @@
 -- Name: detail
 -- Notes:
 -- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT
@@ -81,6 +81,30 @@ FROM (
               JOIN site() ON (warehous_id=itemsite_warehous_id)
               JOIN item ON (item_id=itemsite_item_id)
               JOIN uom ON (uom_id=coitem_qty_uom_id)
+<? foreach("char_id_text_list") ?>
+     LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?> 
+          ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='SO') 
+         AND  (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=cohead_id)
+         AND  (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))
+     LEFT OUTER JOIN char char_alias<? literal("char_id_text_list") ?> 
+          ON (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=char_alias<? literal("char_id_text_list") ?>.char_id)
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+     LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?> 
+          ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='SO') 
+         AND  (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=cohead_id)
+         AND  (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))
+     LEFT OUTER JOIN char char_alias<? literal("char_id_list_list") ?> 
+          ON (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=char_alias<? literal("char_id_list_list") ?>.char_id)
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+     LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?> 
+          ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='SO') 
+         AND  (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=cohead_id)
+         AND  (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))
+     LEFT OUTER JOIN char char_alias<? literal("char_id_date_list") ?> 
+          ON (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=char_alias<? literal("char_id_date_list") ?>.char_id)
+<? endforeach ?>
   WHERE (coitem_id IN (SELECT coitem_id
                      FROM coitem
                     WHERE coitem_status = 'O'
@@ -150,6 +174,7 @@ FROM (
   <? if exists("warehous_id") ?>
     AND  (itemsite_warehous_id=<? value("warehous_id") ?>)
   <? endif ?>
+  <? literal("charClause") ?>
         )
 
   UNION
@@ -202,6 +227,30 @@ FROM (
               JOIN site() ON (warehous_id=itemsite_warehous_id)
               JOIN item ON (item_id=itemsite_item_id)
               JOIN uom ON (uom_id=coitem_qty_uom_id)
+<? foreach("char_id_text_list") ?>
+     LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?> 
+          ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='SO') 
+         AND  (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=cohead_id)
+         AND  (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))
+     LEFT OUTER JOIN char char_alias<? literal("char_id_text_list") ?> 
+          ON (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=char_alias<? literal("char_id_text_list") ?>.char_id)
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+     LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?> 
+          ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='SO') 
+         AND  (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=cohead_id)
+         AND  (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))
+     LEFT OUTER JOIN char char_alias<? literal("char_id_list_list") ?> 
+          ON (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=char_alias<? literal("char_id_list_list") ?>.char_id)
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+     LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?> 
+          ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='SO') 
+         AND  (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=cohead_id)
+         AND  (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))
+     LEFT OUTER JOIN char char_alias<? literal("char_id_date_list") ?> 
+          ON (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=char_alias<? literal("char_id_date_list") ?>.char_id)
+<? endforeach ?>
   WHERE ( (coitem_status='O')
   <? if exists("cohead_id") ?>
     AND  (coitem_cohead_id=<? value("cohead_id") ?>)
@@ -266,6 +315,7 @@ FROM (
   <? if exists("warehous_id") ?>
     AND  (itemsite_warehous_id=<? value("warehous_id") ?>)
   <? endif ?>
+  <? literal("charClause") ?>
         )
 
 ) AS dummy
index f3fbfa3..0973a39 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: bankrec
 -- Name: checks
 -- Notes: used by reconcileBankaccount
---        Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 --        See www.xtuple.com/CPAL for the full text of the software license.
 
 <? if exists("summary") ?>
index 1ba3268..d251cd2 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: bankrec
 -- Name: clearedbalance
 -- Notes: used by reconcileBankaccount
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT (COALESCE(SUM(amount),0.0) + <? value("begBal") ?>) AS cleared_amount,
index 6116ec9..82053eb 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: bankrec
 -- Name: receipts
 -- Notes: used by reconcileBankaccount
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 <? if exists("summary") ?>
index 278d7a6..e6db42d 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: bankrecHistory
 -- Name: reconciled
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 <? if exists("treeView") ?>
index 6b1f69c..7bf7484 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: bankrecHistory
 -- Name: unreconciled
 -- Notes: 
---        Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 --        See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT gltrans_id, gltrans_date, formatDate(gltrans_date) AS f_date,
index 5df28c9..864b03b 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: billingSelections
 -- Name: detail
 -- Notes: used by dspBillingSelections
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT cobmisc_id, cohead_id,
index 8728482..4960f3b 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: bom
 -- Name: detail
 -- Notes: used by dspIndentedBOM, dspSingleLevelBOM, dspSummarizedBOM
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT <? if exists("bySingleLvl") ?>
index 7b94774..16ebdc7 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: bomItems
 -- Name: detail
 -- Notes: used by bom, booItem
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT bomitem_id, item_id, *,
index 873dc9e..6214403 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: bookings
 -- Name: detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT   coitem_id AS id, coitem_cohead_id AS altId,
@@ -60,6 +60,30 @@ SELECT   coitem_id AS id, coitem_cohead_id AS altId,
               JOIN item ON (item_id=itemsite_item_id)
               JOIN uom ON (uom_id=coitem_qty_uom_id)
               JOIN curr_symbol ON (curr_id=cohead_curr_id)
+<? foreach("char_id_text_list") ?>
+     LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?> 
+          ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='SO') 
+         AND  (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=cohead_id)
+         AND  (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))
+     LEFT OUTER JOIN char char_alias<? literal("char_id_text_list") ?> 
+          ON (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=char_alias<? literal("char_id_text_list") ?>.char_id)
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+     LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?> 
+          ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='SO') 
+         AND  (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=cohead_id)
+         AND  (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))
+     LEFT OUTER JOIN char char_alias<? literal("char_id_list_list") ?> 
+          ON (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=char_alias<? literal("char_id_list_list") ?>.char_id)
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+     LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?> 
+          ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='SO') 
+         AND  (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=cohead_id)
+         AND  (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))
+     LEFT OUTER JOIN char char_alias<? literal("char_id_date_list") ?> 
+          ON (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=char_alias<? literal("char_id_date_list") ?>.char_id)
+<? endforeach ?>
   WHERE ( (coitem_status<>'X')
   <? if exists("cohead_id") ?>
     AND  (coitem_cohead_id=<? value("cohead_id") ?>)
@@ -112,6 +136,7 @@ SELECT   coitem_id AS id, coitem_cohead_id AS altId,
   <? if exists("warehous_id") ?>
     AND  (itemsite_warehous_id=<? value("warehous_id") ?>)
   <? endif ?>
+  <? literal("charClause") ?>
         )
 
 <? if exists("orderByScheddate") ?>
index 8294c0b..619f501 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: briefEarnedCommission
 -- Name: detail
 -- Notes: used by dspBriefEarnedCommissions
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT cohist_salesrep_id, salesrep_number, salesrep_name, cust_number, cust_name,
index 2eec19b..8dc7a25 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: briefSalesHistory
 -- Name: detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT
index 7d94e62..972d764 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: capacityUOMs
 -- Name: detail
 -- Notes: used by dspCapacityUOMsByClassCode, dspCapacityUOMsByProductCategory
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT item_id, item_number,
index 478b8f9..0464b98 100644 (file)
@@ -4,7 +4,7 @@
 -- There are 2 display modes for this query:
 -- 1) Legacy mode which uses A/R Application information
 -- 2) Version 3.3.0 upgrade mode which uses Cash Receipt information
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 <? if exists("LegacyDisplayMode") ?>
index 040e4b8..e61c3c8 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: ccpayments
 -- Name:  list
 -- Notes: list credit card payments, optionally by customer
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT ccpay_id AS id, 
index 1cd2030..311e637 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: charass
 -- Name:  populate
 -- Notes: Populate characteristic assignments combobox
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 <? if exists("name") ?>
index a0e6ed2..87d6cae 100644 (file)
@@ -5,7 +5,7 @@
 --        check number(optional), and recipient(optional), optionally restricted
 --        to 'new' (un-posted/replaced/deleted) checks for viewing check runs.
 --        fills in the check item detail if showDetail is passed.
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT checkhead_id AS checkid,
@@ -84,7 +84,11 @@ UNION
 SELECT checkitem_checkhead_id AS checkid, 0 AS extra, checkitem_id,
        checkhead_void, checkhead_misc,
        checkhead_printed, checkhead_posted,
-       CAST(COALESCE(checkitem_ranumber, checkitem_vouchernumber) AS TEXT) AS number,
+       (CASE apopen_doctype WHEN 'V' THEN <? value("voucher") ?>
+                            WHEN 'D' THEN <? value("debitMemo") ?>
+                            WHEN 'C' THEN <? value("creditMemo") ?>
+                            ELSE ''
+        END || '-' || CAST(COALESCE(checkitem_ranumber, checkitem_vouchernumber) AS TEXT)) AS number,
        CAST(COALESCE(checkitem_invcnumber, checkitem_cmnumber) AS TEXT) AS description,
        CAST(NULL AS DATE) AS checkdate,
        checkitem_amount AS amount,
@@ -98,9 +102,9 @@ SELECT checkitem_checkhead_id AS checkid, 0 AS extra, checkitem_id,
        '' AS checkhead_void_qtdisplayrole,    '' AS checkhead_misc_qtdisplayrole,
        '' AS checkhead_printed_qtdisplayrole, '' AS checkhead_posted_qtdisplayrole,
        1 AS xtindentrole
-  FROM checkitem, checkhead 
WHERE ((checkitem_checkhead_id=checkhead_id)
  AND   (checkhead_bankaccnt_id=<? value("bankaccnt_id") ?>)
+  FROM checkhead JOIN checkitem ON (checkitem_checkhead_id=checkhead_id)
                LEFT OUTER JOIN apopen ON (apopen_id=checkitem_apopen_id)
WHERE ((checkhead_bankaccnt_id=<? value("bankaccnt_id") ?>)
    <? if exists("startDate") ?>
      AND   (checkhead_checkdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)
    <? elseif exists("newOnly") ?>
index f88e712..64e6ac1 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: checks
 -- Name: detail
 -- Notes: used by printChecks
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT checkhead.*, form_report_name AS report_name
index 4451c2b..ffd5328 100644 (file)
@@ -3,7 +3,7 @@
 -- Notes: This query determines whether a given contact should be kept
 --        active because other active records depend on it.
 --        Todo - should this be moved to the cntctAfterTrigger?
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT EXISTS(
index 8621879..63e2137 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: contact
 -- Name:  uses
 -- Notes: Find and report uses of the contact
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 <? if not exists('core') ?>
index 49e4912..c2a610f 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: contactmerge
 -- Name: contactused
 -- Notes: Checks to see if this contact is used anywhere
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT cntctused(<? value("cntct_id") ?>) AS used;
index 52bc1e8..98a2446 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: contactmerge
 -- Name: delete
 -- Notes: Delete a contact
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 DELETE FROM cntct WHERE (cntct_id=<? value("cntct_id") ?>);
index d1f13d5..0ea3d61 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: contactmerge
 -- Name: deselect
 -- Notes: Removes contact selection
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 DELETE FROM cntctsel
index c7f1b01..1b788eb 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: contactmerge
 -- Name: merge
 -- Notes: Merge contact selections
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT cntctmerge(
index 9a9ffd7..973917a 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: contactmerge
 -- Name: merged
 -- Notes:  Lists all merged contacts
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT cntct_id,
index 1766597..28574f6 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: contactmerge
 -- Name: populate
 -- Notes: Queries selected contact info
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT cntct.*,
index 795b5bd..fb498d7 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: contactmerge
 -- Name: purge
 -- Notes: Purge contact(s) that was/were previously merged
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 DELETE FROM cntct WHERE cntct_id IN
index 61186da..7619e95 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: contactmerge
 -- Name: restore
 -- Notes: Restore a contact that was previously merged
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT cntctrestore(cntctmrgd_cntct_id) AS result
index 35c6e20..de68a48 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: contactmerge
 -- Name: search
 -- Notes: Search for contacts
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT cntct_id,
index 733d816..fae89e5 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: contactmerge
 -- Name: select
 -- Notes: Processes contact selections
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT cntctselect(
index 4d473e3..c9d5bb5 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: contactmerge
 -- Name: selectcol
 -- Notes: Selects a specific column
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT cntctselectcol(<? value("cntct_id") ?>, <? value("col_number") ?>);
index 25a442d..e613666 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: contacts
 -- Name: detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT DISTINCT ON (length(cntct_last_name)=0, length(cntct_first_name)=0, cntct_last_name, cntct_first_name, cntct_number) 
diff --git a/foundation-database/public/tables/metasql/contract-itemsources.mql b/foundation-database/public/tables/metasql/contract-itemsources.mql
new file mode 100644 (file)
index 0000000..e24c533
--- /dev/null
@@ -0,0 +1,135 @@
+-- Group: contract
+-- Name:  itemsources
+-- Notes: Selection of Contract Related Item Sources
+SELECT itemsrc_id,
+       -1 AS pohead_id, 
+       ' ' AS seq,
+       ' ' AS poitem_ordnumber, 
+        item_number,
+       item_descrip1,
+       itemsrc_vend_uom,
+       itemsrc_vend_item_number,
+       itemsrc_contrct_min,
+       sum(poitem_qty_unreleased) AS poitem_qty_unreleased,
+       sum(poitem_qty_ordered)    AS poitem_qty_ordered,
+       sum(poitem_qty_received)   AS poitem_qty_received,
+       sum(poitem_qty_returned)   AS poitem_qty_returned,
+       null AS poitem_duedate,
+       null AS poitem_status,
+       0 AS xtindentrole 
+       FROM (SELECT contrct_id, 
+               itemsrc_id,
+               pohead_number || '-' || ltrim(to_char(poitem_linenumber, '999')) AS poitem_ordnumber, 
+               item_number,
+               item_descrip1,
+               itemsrc_vend_uom,
+               itemsrc_vend_item_number,
+               itemsrc_contrct_min,
+               CASE WHEN poitem_status = 'U' THEN poitem_qty_ordered
+                 ELSE 0
+               END AS poitem_qty_unreleased,
+               CASE WHEN poitem_status = 'O' THEN poitem_qty_ordered
+                    WHEN poitem_status = 'C' THEN poitem_qty_ordered
+                  ELSE 0
+               END AS poitem_qty_ordered,
+               poitem_qty_received,
+               poitem_qty_returned,
+               poitem_duedate, 
+               poitem_status
+               FROM contrct JOIN itemsrc  ON (itemsrc_contrct_id  = contrct_id)
+                 LEFT OUTER JOIN poitem   ON (poitem_itemsrc_id   = itemsrc_id)
+                 LEFT OUTER JOIN pohead   ON (pohead_id           = poitem_pohead_id)
+                            JOIN item     ON (itemsrc_item_id     = item_id)
+               WHERE (contrct_id = <? value("contrct_id") ?>)) AS dummy1
+       WHERE (contrct_id = <? value("contrct_id") ?>)
+       GROUP BY itemsrc_id, itemsrc_vend_item_number, itemsrc_vend_uom, itemsrc_contrct_min,
+                item_number, item_descrip1
+
+UNION  -- PO Line Items
+
+SELECT itemsrc_id,
+       pohead_id, 
+       pohead_number || '-' || ltrim(to_char(poitem_linenumber, '999')) AS seq,
+        pohead_number || '-' || ltrim(to_char(poitem_linenumber, '999')) AS poitem_ordnumber,  
+        null AS item_number,
+       null AS item_descrip1,
+       null AS itemsrc_vend_uom,
+       null AS itemsrc_vend_item_number,
+       null AS itemsrc_contrct_min,
+       CASE WHEN poitem_status = 'U' THEN poitem_qty_ordered
+         ELSE 0
+       END AS poitem_qty_unreleased,
+       CASE WHEN poitem_status = 'O' THEN poitem_qty_ordered
+            WHEN poitem_status = 'C' THEN poitem_qty_ordered
+          ELSE 0
+       END AS poitem_qty_ordered,
+       poitem_qty_received,
+       poitem_qty_returned,
+       poitem_duedate, 
+       CASE WHEN poitem_status = 'O' THEN 'Open'
+            WHEN poitem_status = 'C' THEN 'Closed'
+            ELSE 'Unreleased'
+       END AS poitem_status,
+       1 AS xtindentrole 
+       FROM contrct JOIN itemsrc  ON (itemsrc_contrct_id  = contrct_id)
+                    JOIN poitem   ON (poitem_itemsrc_id   = itemsrc_id)
+                    JOIN pohead   ON (pohead_id           = poitem_pohead_id)
+                    JOIN itemsite ON (poitem_itemsite_id  = itemsite_id)
+                    JOIN item     ON (itemsite_item_id    = item_id)
+       WHERE (contrct_id = <? value("contrct_id") ?>)
+
+UNION -- Receipts
+
+SELECT itemsrc_id,
+       pohead_id,  
+       poitem_ordnumber || 'R' || to_char(recv_date, 'YYYYMMDDHH24:MI:SS') AS seq,
+       'Receipt' AS poitem_ordnumber,
+       null AS item_number,
+       null AS item_descrip1,
+       recv_vend_uom AS vend_uom,
+       null AS itemsrc_vend_item_number,
+       null AS itemsrc_contrct_min,
+       null AS poitem_qty_unreleased,
+       null AS poitem_qty_ordered,
+       recv_qty AS poitem_qty_received,
+       null AS poitem_qty_returned,
+       recv_date AS poitem_duedate,
+       recv_trans_usr_name AS username,
+       2 AS xtindentrole
+  FROM recv JOIN (SELECT pohead_number || '-' || ltrim(to_char(poitem_linenumber, '999')) AS poitem_ordnumber, 
+                           poitem_pohead_id, poitem_linenumber, poitem_id, pohead_id, 
+                           poitem_itemsrc_id
+                       FROM poitem JOIN pohead ON (pohead_id = poitem_pohead_id)) AS dummy ON (poitem_id   = recv_orderitem_id)
+               JOIN itemsite ON (itemsite_id = recv_itemsite_id)
+               JOIN item     ON (item_id     = itemsite_item_id)
+               JOIN itemsrc  ON (poitem_itemsrc_id = itemsrc_id)
+  WHERE (itemsrc_contrct_id = <? value("contrct_id") ?>) 
+
+UNION -- Returns
+
+SELECT itemsrc_id, 
+       pohead_id,  
+       poitem_ordnumber || 'R' || to_char(poreject_date, 'YYYYMMDDHH24:MI:SS') AS seq,
+       'Return' AS poitem_ordnumber,
+       null AS item_number,
+       null AS item_descrip1,
+       poreject_vend_uom AS vend_uom,
+       null AS itemsrc_vend_item_number,
+       null AS itemsrc_contrct_min,
+       null AS poitem_qty_unreleased,
+       null AS poitem_qty_ordered,
+       null AS poitem_qty_received,
+       poreject_qty AS poitem_qty_returned,
+       poreject_date AS poitem_duedate,
+       poreject_trans_username AS username,
+       2 AS xtindentrole 
+  FROM poreject JOIN (SELECT pohead_number || '-' || ltrim(to_char(poitem_linenumber, '999')) AS poitem_ordnumber, 
+                           poitem_pohead_id, poitem_linenumber, poitem_id, pohead_id, 
+                           poitem_itemsrc_id
+                       FROM poitem JOIN pohead ON (pohead_id = poitem_pohead_id)) AS dummy ON (poitem_id   = poreject_poitem_id)
+               JOIN itemsite ON (itemsite_id = poreject_itemsite_id)
+               JOIN item     ON (item_id     = itemsite_item_id)
+               JOIN itemsrc  ON (poitem_itemsrc_id = itemsrc_id)
+  WHERE (itemsrc_contrct_id = <? value("contrct_id") ?>) 
+
+ORDER BY itemsrc_id, seq, poitem_ordnumber, poitem_duedate, xtindentrole;
index 35c26fc..6959c89 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: contracts
 -- Name: detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT contrct_id, 
index 61f5d0a..4c47ac8 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: costedBOM
 -- Name: detail
 -- Notes: used by dspCostedIndentedBOM, dspCostedSingleLevelBOM, dspCostedSummarizedBOM
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT
index 3ca354e..827ffef 100644 (file)
@@ -2,7 +2,7 @@
 -- Name:  unusedbyitem
 -- Notes: list the cost elements that can be applied to an item that have
 --        not already been applied to that item. takes an item_id and type.
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 <? if exists("item_id") ?>
index 0a1d398..c82b060 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: countSlip
 -- Name: detail
 -- Notes: used by dspCountSlipEditList, dspCountSlipsByWarehouse
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT cntslip_id,
index 894211f..a930353 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: countTag
 -- Name: detail
 -- Notes: used by dspCountTagEditList
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT *,
index 521c451..7380bc6 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: countTags
 -- Name: create
 -- Notes: used by createCountTagsByParameterList
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT createCountTag(itemsite_id, <? value("comments") ?>, <? value("priority") ?>, <? value("freeze") ?>, <? value("location_id") ?>)
index baab2ed..77bf49f 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: countTags
 -- Name: detail
 -- Notes: used by dspCountTagsByClassCode, dspCountTagsByItem, dspCountTagsByWarehouse
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT invcnt_id, invcnt_tagnumber, warehous_code,
index 9b12ff0..c7eca30 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: creditCards
 -- Name: detail
 -- Notes: used by cashReceipt, customer, salesOrder
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT ccard_id, ccard_seq,
index 8f38bf7..0fc388d 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: creditMemo
 -- Name: editlist
 -- Notes: used by creditMemoEditList
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT *,
index c7a23a5..5419abd 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: creditMemoCreditCards
 -- Name: detail
 -- Notes: used by arWorkBench, returnAuthorization, returnAuthorizationWorkbench
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT cmhead_number, cmhead_freight, cmhead_curr_id,
index d3035ca..5d9eedf 100644 (file)
@@ -3,7 +3,7 @@
 -- Notes: select details about countries used throughout the database
 --        that do not match country.country_name
 --
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 <? if exists("count") ?>
index e24203c..dc66ba0 100644 (file)
@@ -2,7 +2,7 @@
 -- Name:  pickdatasources
 -- Notes: Show the records the user has selected to merge crm accounts. Emphasize
 --        the particular fields in each record that s/he has selected.
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT c.crmacct_id,
index c1596a2..9197dd9 100644 (file)
@@ -4,7 +4,7 @@
 --        data to purge. this includes those that have been started
 --        but not completed as well as those that have been completed
 --        but neither purged nor undone.
---        Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 --        See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT DISTINCT
index 7b5fad6..e4683a1 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: crmaccounts
 -- Name:  detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT DISTINCT ON (crmacct_number)
index 7b6b74a..d466c39 100644 (file)
@@ -3,7 +3,7 @@
 -- Notes: used by currencyConversions
 --        the N in round(curr_rate, N) has to be SCALE - 1 of curr_rates
 --        NUMERIC(p, SCALE) type definition
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT curr_rate_id, currConcat(curr_id) AS f_curr,
index b05b456..fd9b159 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: customers
 -- Name:  detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT DISTINCT ON ( cust_number ) 
@@ -10,6 +10,7 @@ SELECT DISTINCT ON ( cust_number )
   custtype_code,
   bill_cntct.cntct_first_name AS bill_first_name,
   bill_cntct.cntct_last_name AS bill_last_name,
+  bill_cntct.cntct_title AS bill_title,
   bill_cntct.cntct_phone AS bill_phone,
   bill_cntct.cntct_fax AS bill_fax,
   bill_cntct.cntct_email AS bill_email,
index fe17554..5b0c104 100644 (file)
@@ -27,7 +27,7 @@
 --             CASE WHEN (aropen_doctype IN ('C', 'R')) THEN -1
 --                  ELSE 1 END) > 0)
 --ORDER BY cust_number;
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT araging_cust_id AS cust_id,
index 0de2e69..83331e9 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: depositesRegister
 -- Name: detail
 -- Notes: used by dspDepositsRegister
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT trans_id, trans_date, trans_source,
index bf73197..69e0fb5 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: detailedInventoryHistory
 -- Name: detail
 -- Notes: used by dspDetailedInventoryHistoryByLocation, dspDetailedInventoryHistoryByLotSerial
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT
index f6ad79a..7a95ea0 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: distributeInventory
 -- Name: locations
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT id, type, locationname, defaultlocation,
index 53549df..a85ed64 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: employees
 -- Name:  detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT emp_id, warehous_code, emp_active, emp_code, emp_number,
index 0e21515..a7a3bad 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: events
 -- Name: detail
 -- Notes: used by eventManager
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT evntlog_id, evntlog_ord_id, evntlog_newdate,
index af21406..b5e683e 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: expiredInventory
 -- Name: detail
 -- Notes: used by dspExpiredInventoryByClassCode
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT itemsite_id, itemloc_id, warehous_code, item_number, uom_name,
index 6c3ec0b..3c354aa 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: freightPrices
 -- Name: detail
 -- Notes: used by dspFreightPricesByCustomer, dspFreightPricesByCustomerType
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT itemid, sourcetype, ipshead_name, source, ipsfreight_qtybreak, ipsfreight_price,
index c2124c8..89bbc0f 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: frozenItemSites
 -- Name: detail
 -- Notes: used by dspFrozenItemSites
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT itemsite_id, warehous_code, item_number,
index c670b9d..3174343 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: glseries
 -- Name:  checkeditable
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT gltrans_id 
index 6688a5e..394d2a1 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: glseries
 -- Name:  detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT *, 
index 438f6a9..c9c7a51 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: glseries
 -- Name:  postjournal
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT postJournals(<? value("sequence") ?>) AS result;
index bb6c5dc..2632a3e 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: gltransactions
 -- Name:  detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT gltrans_id, gltrans_accnt_id,gltrans_date,gltrans_created,gltrans_source,
index 493de11..051785e 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: incidents 
 -- Name: detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT DISTINCT ON (incdt_number) incdt_id AS id,
index 0e3d6b9..de95654 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: invalidBillsofMaterials
 -- Name: detail
 -- Notes: used by dspInvalidBillsOfMaterials
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT itemsite_id, parent.item_id AS pitem_id,
index 44c55a6..db9fd15 100644 (file)
@@ -2,7 +2,7 @@
 -- Name:  byCustOrSO
 -- Notes: query to get item availability by either customer id/type/pattern
 --        or by cohead_id
---        Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 --        See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT id, altid, cohead_id,
index 8ebb906..ddeabd6 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: inventoryAvailability
 -- Name:  general
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT itemsite_id, altId,
index da006fc..b966fc9 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: inventoryAvailabilitybyWorkorder
 -- Name: detail
 -- Notes: used by dspInventoryAvailabilityByWorkOrder
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT *, 'qty' AS woinvav_qoh_xtnumericrole,
index 15131bb..bed7629 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: inventoryHistory
 -- Name: detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT invhist_id, invdetail_id, invhist_transdate AS sortdate,
index dccb900..90bfa43 100644 (file)
@@ -1,7 +1,8 @@
 -- Group: inventoryLocator
 -- Name: detail
 -- Notes: used by dspInventoryLocator
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- Lot/Serial Characteristics additions by Specter Vision Solutions, Inc.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT *,
@@ -32,8 +33,35 @@ FROM (SELECT itemloc_id, 1 AS type, warehous_code,
              CASE WHEN (itemsite_warrpurc) THEN itemloc_warrpurc
              END AS warranty,
              itemloc_qty AS qoh
+<? foreach("char_id_text_list") ?>
+  , charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+  , charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+  , charass_alias<? literal("char_id_date_list") ?>.charass_value::date AS char<? literal("char_id_date_list") ?>
+<? endforeach ?>
       FROM itemsite, whsinfo,
            itemloc LEFT OUTER JOIN location ON (itemloc_location_id=location_id)
+<? foreach("char_id_text_list") ?>
+  LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?> ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='LS')
+                                                                    AND  (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=itemloc_ls_id)
+                                                                    AND  (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))
+  LEFT OUTER JOIN char char_alias<? literal("char_id_text_list") ?> ON (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=char_alias<? literal("char_id_text_list") ?>.char_id)
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+  LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?> ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='LS')
+                                                                    AND  (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=itemloc_ls_id)
+                                                                    AND  (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))
+  LEFT OUTER JOIN char char_alias<? literal("char_id_list_list") ?> ON (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=char_alias<? literal("char_id_list_list") ?>.char_id)
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+  LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?> ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='LS')
+                                                                    AND  (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=itemloc_ls_id)
+                                                                    AND  (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))
+  LEFT OUTER JOIN char char_alias<? literal("char_id_date_list") ?> ON (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=char_alias<? literal("char_id_date_list") ?>.char_id)
+<? endforeach ?>
       WHERE ((itemsite_loccntrl OR (itemsite_controlmethod IN ('L', 'S')))
          AND (itemloc_itemsite_id=itemsite_id)
          AND (itemsite_warehous_id=warehous_id)
@@ -41,6 +69,16 @@ FROM (SELECT itemloc_id, 1 AS type, warehous_code,
       <? if exists("warehous_id") ?>
          AND (itemsite_warehous_id=<? value("warehous_id") ?>)
       <? endif ?>
+      <? if exists("site") ?>
+         AND (itemsite_warehous_id=<? value("site")?>)
+      <? endif ?>
+      <? if exists("lot_serial") ?>
+         AND (formatlotserialnumber(itemloc_ls_id)=<? value("lot_serial")?>)
+      <? endif ?>
+      <? if exists("_location_name") ?>
+         AND (formatLocationName(location_id)=<? value("_location_name")?>)
+      <? endif ?>
+      <? literal("charClause") ?>
             )
       UNION
       SELECT itemsite_id, 2 AS type, warehous_code,
@@ -52,6 +90,15 @@ FROM (SELECT itemloc_id, 1 AS type, warehous_code,
              NULL AS expiration,
              NULL AS warranty,
              itemsite_qtyonhand AS qoh
+<? foreach("char_id_text_list" ?>
+          , NULL AS char<? value("char_id_text_list") ?>
+<? endforeach ?>
+<? foreach("char_id_list_list" ?>
+          , NULL AS char<? value("char_id_list_list") ?>
+<? endforeach ?>
+<? foreach("char_id_date_list" ?>
+          , NULL AS char<? value("char_id_date_list") ?>
+<? endforeach ?>
       FROM itemsite, whsinfo
       WHERE ((NOT itemsite_loccntrl)
          AND (itemsite_controlmethod NOT IN ('L', 'S'))
index 4769eee..84dcffa 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: invoiceInformation
 -- Name: detail
 -- Notes: used by dspInvoiceInformation
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT arapply_id,
index c973095..3dd9d84 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: invoiceRegister
 -- Name: detail
 -- Notes: used by dspInvoiceRegister
---        Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 --        See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT DISTINCT *
index f3f01c5..67ee698 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: invoices
 -- Name: detail
 -- Notes: used by reprintInvoices, unpostedInvoices, dspRecurringInvoices
---        Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 --        See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT invchead_id, cust_id,
@@ -29,6 +29,11 @@ SELECT invchead_id, cust_id,
          invchead_invcnumber AS docnumber,
          findCustomerForm(cust_id, 'I') AS reportname,
        <? endif ?>
+       CASE WHEN (calcInvoiceAmt(invchead_id,'S') != 0.0)
+              THEN (calcInvoiceAmt(invchead_id,'M') / calcInvoiceAmt(invchead_id,'S'))
+            ELSE 1.0
+       END AS marginpercent,
+       'percent' AS marginpercent_xtnumericrole,
        'curr' AS extprice_xtnumericrole,
        'curr' AS balance_xtnumericrole,
        CASE WHEN (aropen_id IS NULL) THEN 'Unposted' END AS balance_qtdisplayrole
index 66e5c32..16146fd 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: invoices
 -- Name: print
 -- Notes: used by printInvoices
---        Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 --        See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT invchead_id,          invchead_id         AS docid,
index 9c9ed0c..946fc14 100644 (file)
@@ -1,11 +1,12 @@
 -- Group: issueToShipping
 -- Name:  detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT *,
        noNeg(qtyord - qtyshipped + qtyreturned) AS balance,
+       indent AS xtindentrole,
        'qty' AS qtyord_xtnumericrole,
        'qty' AS qtyshipped_xtnumericrole,
        'qty' AS qtyreturned_xtnumericrole,
@@ -18,13 +19,10 @@ SELECT *,
 FROM (
 <? if exists("sohead_id") ?>
 SELECT coitem_id AS lineitem_id, 
-       CASE 
-         WHEN (itemsite_costmethod = 'J') THEN 
-           1 
-         ELSE 
-           0 
-       END AS job, 
-       MIN(s1.shiphead_number) AS shiphead_number, 
+       CASE WHEN (itemsite_costmethod = 'J') THEN 1 
+            ELSE 0 
+       END AS job, 0 AS indent,
+       getOpenShipment('SO', <? value("sohead_id") ?>, <? value("warehous_id") ?>) AS shiphead_number, 
        formatSoLineNumber(coitem_id) AS linenumber, item_number,
        (item_descrip1 || ' ' || item_descrip2) AS itemdescrip,
        warehous_code,
@@ -33,37 +31,84 @@ SELECT coitem_id AS lineitem_id,
        coitem_qtyord AS qtyord,
        coitem_qtyshipped AS qtyshipped,
        coitem_qtyreturned AS qtyreturned,
-       COALESCE(SUM(shipitem_qty), 0) AS atshipping, 
-       coitem_linenumber AS seq1, coitem_subnumber AS seq2 
-FROM itemsite, item, site(), uom,
-     coitem LEFT OUTER JOIN
-      ( shipitem JOIN shiphead s1
-        ON ( (shipitem_shiphead_id=s1.shiphead_id) 
-         AND (s1.shiphead_order_type='SO') 
-         AND (NOT s1.shiphead_shipped) )
-      ) ON  (shipitem_orderitem_id=coitem_id) 
--- TODO - need a facility to select which shipment you are working on
---     LEFT OUTER JOIN shiphead s2 ON ((s2.shiphead_order_id=coitem_cohead_id) 
---                                 AND (s2.shiphead_order_type='SO') 
---                                  AND (NOT s2.shiphead_shipped )) 
-WHERE ( (coitem_itemsite_id=itemsite_id)
- AND (coitem_qty_uom_id=uom_id)
- AND (itemsite_item_id=item_id)
- AND (itemsite_warehous_id=warehous_id)
- AND (coitem_status NOT IN ('C','X'))
- AND (item_type != 'K')
- AND (coitem_cohead_id=<? value("sohead_id") ?>) ) 
-GROUP BY coitem_id, linenumber, item_number,
-         item_descrip1, item_descrip2, warehous_code,
-         coitem_scheddate, uom_name,
-         coitem_qtyord, coitem_qtyshipped, coitem_qtyreturned, 
-         coitem_linenumber, coitem_subnumber, 
---         s2.shiphead_number, 
-         itemsite_costmethod, itemsite_controlmethod 
+       qtyAtShipping(coitem_id) AS atshipping, 
+       coitem_scheddate AS seq1, coitem_linenumber AS seq2, coitem_subnumber AS seq3 
+FROM coitem JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
+            JOIN item ON (item_id=itemsite_item_id)
+            JOIN site() ON (warehous_id=itemsite_warehous_id)
+            JOIN uom ON (uom_id=coitem_qty_uom_id)
+WHERE ( (coitem_status NOT IN ('C','X'))
+  AND   (item_type != 'K')
+<? if exists("warehous_id") ?>
+  AND   (itemsite_warehous_id=<? value("warehous_id") ?>) 
+<? endif ?>
+  AND   (coitem_cohead_id=<? value("sohead_id") ?>) ) 
+
+<? if exists("includeReservations") ?>
+UNION ALL
+SELECT coitem_id AS lineitem_id, 
+       CASE WHEN (itemsite_costmethod = 'J') THEN 1 
+            ELSE 0 
+       END AS job, 1 AS indent,
+       '' AS shiphead_number, 
+       '' AS linenumber, formatLocationName(itemloc_location_id) AS item_number,
+       formatLotSerialNumber(itemloc_ls_id) AS itemdescrip,
+       '' AS warehous_code,
+       NULL AS scheddate,
+       '' AS uom_name,
+       reserve_qty AS qtyord,
+       NULL AS qtyshipped,
+       NULL AS qtyreturned,
+       NULL AS atshipping, 
+       coitem_scheddate AS seq1, coitem_linenumber AS seq2, coitem_subnumber AS seq3 
+FROM coitem JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
+            JOIN item ON (item_id=itemsite_item_id)
+            JOIN site() ON (warehous_id=itemsite_warehous_id)
+            JOIN reserve ON (reserve_demand_id=coitem_id AND
+                             reserve_demand_type='SO' AND
+                             reserve_supply_type='I')
+            JOIN itemloc ON (itemloc_id=reserve_supply_id)
+WHERE ( (coitem_status NOT IN ('C','X'))
+  AND   (item_type != 'K')
+  AND   ((itemsite_controlmethod IN ('L', 'S')) OR (itemsite_loccntrl))
+<? if exists("warehous_id") ?>
+  AND   (itemsite_warehous_id=<? value("warehous_id") ?>) 
+<? endif ?>
+  AND   (coitem_cohead_id=<? value("sohead_id") ?>) ) 
+UNION ALL
+SELECT coitem_id AS lineitem_id, 
+       CASE WHEN (itemsite_costmethod = 'J') THEN 1 
+            ELSE 0 
+       END AS job, 1 AS indent,
+       '' AS shiphead_number, 
+       '' AS linenumber, 'N/A',
+       'N/A' AS itemdescrip,
+       '' AS warehous_code,
+       NULL AS scheddate,
+       '' AS uom_name,
+       coitem_qtyreserved AS qtyord,
+       NULL AS qtyshipped,
+       NULL AS qtyreturned,
+       NULL AS atshipping, 
+       coitem_scheddate AS seq1, coitem_linenumber AS seq2, coitem_subnumber AS seq3 
+FROM coitem JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
+            JOIN item ON (item_id=itemsite_item_id)
+            JOIN site() ON (warehous_id=itemsite_warehous_id)
+WHERE ( (coitem_status NOT IN ('C','X'))
+  AND   (item_type != 'K')
+  AND   ((itemsite_controlmethod = 'R') AND (NOT itemsite_loccntrl))
+  AND   (coitem_qtyreserved > 0.0)
+<? if exists("warehous_id") ?>
+  AND   (itemsite_warehous_id=<? value("warehous_id") ?>) 
+<? endif ?>
+  AND   (coitem_cohead_id=<? value("sohead_id") ?>) ) 
+<? endif ?>
+
 <? elseif exists("tohead_id") ?>
+
 SELECT toitem_id AS lineitem_id, 
-       0 AS lsJob, 
-       MIN(s1.shiphead_number) AS shiphead_number, 
+       0 AS lsJob, 0 AS indent,
+       getOpenShipment('TO', <? value("tohead_id") ?>, <? value("warehous_id") ?>) AS shiphead_number, 
        toitem_linenumber AS linenumber, item_number,
        (item_descrip1 || ' ' || item_descrip2) AS itemdescrip,
        tohead_srcname AS warehous_code,
@@ -72,30 +117,18 @@ SELECT toitem_id AS lineitem_id,
        toitem_qty_ordered AS qtyord,
        toitem_qty_shipped AS qtyshipped,
        0 AS qtyreturned,
-       COALESCE(SUM(shipitem_qty), 0) AS atshipping, 
-       toitem_linenumber AS seq1, 0 AS seq2 
-FROM item, tohead, site(), uom,
-     toitem LEFT OUTER JOIN
-      ( shipitem JOIN shiphead s1
-        ON ( (shipitem_shiphead_id=s1.shiphead_id) 
-         AND (s1.shiphead_order_type='TO') 
-         AND (NOT s1.shiphead_shipped) )
-      ) ON  (shipitem_orderitem_id=toitem_id) 
--- TODO - need a facility to select which shipment you are working on
---     LEFT OUTER JOIN shiphead s2 ON ((s2.shiphead_order_id=toitem_tohead_id) 
---                                 AND (s2.shiphead_order_type='TO') 
---                                 AND (NOT s2.shiphead_shipped )) 
+       qtyAtShipping('TO', toitem_id) AS atshipping, 
+       toitem_schedshipdate AS seq1, toitem_linenumber AS seq2, 0 AS seq3 
+FROM item, tohead, site(), uom, toitem
 WHERE ( (toitem_item_id=item_id)
  AND (toitem_status NOT IN ('C','X'))
  AND (toitem_tohead_id=tohead_id)
  AND (tohead_src_warehous_id=warehous_id)
  AND (item_inv_uom_id=uom_id)
+<? if exists("warehous_id") ?>
+  AND   (tohead_src_warehous_id=<? value("warehous_id") ?>) 
+<? endif ?>
  AND (tohead_id=<? value("tohead_id") ?>) ) 
-GROUP BY toitem_id, toitem_linenumber, item_number,
-         item_descrip1, item_descrip2, tohead_srcname,
-         toitem_schedshipdate, uom_name,
-         toitem_qty_ordered, toitem_qty_shipped 
---         s2.shiphead_number 
 <? endif ?>
 ) AS sub 
-ORDER BY scheddate, seq1, seq2;
+ORDER BY seq1, seq2, seq3, indent;
index 2fd5ee9..67dd1f6 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: itemCost
 -- Name: detail
 -- Notes: used by dspItemCostSummary, dspItemCostsByClassCode, dspItemCostHistory
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT 
index 242e43f..63460c5 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: itemCost
 -- Name: list
 -- Notes: used by maintainItemCosts, bomItem
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 -- The order of checking for item_id first is important.
index 24ee40c..377f256 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: itemPricingSchedule
 -- Name: detail
 -- Notes: used by itemPricingSchedule
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 
@@ -15,9 +15,18 @@ SELECT ipsitem_id AS id, 1 AS altid,
        price.uom_name AS priceuom,
        ((COALESCE(ipsitem_discntprcnt, 0.0) * 100) + ipsitem_price) AS price,
        (COALESCE(ipsitem_fixedamtdiscount, 0.0) + 0.00) AS fixedAmt,
-       noNeg(CASE WHEN (ipsitem_type='N') THEN ipsitem_price
-                  WHEN (ipsitem_type='D') THEN (item_listprice - (item_listprice * COALESCE(ipsitem_discntprcnt, 0.0)) - COALESCE(ipsitem_fixedamtdiscount, 0.0))
-                  WHEN (ipsitem_type='M') THEN (item_listcost + (item_listcost * COALESCE(ipsitem_discntprcnt, 0.0)) + COALESCE(ipsitem_fixedamtdiscount, 0.0))
+       noNeg(CASE WHEN (ipsitem_type='N') THEN
+                   ipsitem_price
+                  WHEN (ipsitem_type='D') THEN
+                   (item_listprice - (item_listprice * COALESCE(ipsitem_discntprcnt, 0.0)) - COALESCE(ipsitem_fixedamtdiscount, 0.0))
+                  WHEN ((ipsitem_type = 'M') AND fetchMetricBool('Long30Markups') AND fetchMetricBool('WholesalePriceCosting')) THEN
+                   (item_listcost / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
+                  WHEN ((ipsitem_type = 'M') AND fetchMetricBool('Long30Markups')) THEN
+                   (itemCost(itemsite_id) / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
+                  WHEN (ipsitem_type = 'M' AND fetchMetricBool('WholesalePriceCosting')) THEN
+                   (item_listcost + (item_listcost * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
+                  WHEN (ipsitem_type = 'M') THEN
+                   (itemCost(itemsite_id) + (itemCost(itemsite_id) * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
                   ELSE 0.0
              END) AS netPrice,
        CASE WHEN (ipsitem_type='N') THEN <? value("nominal") ?>
@@ -38,6 +47,7 @@ FROM ipsiteminfo LEFT OUTER JOIN item ON (item_id=ipsitem_item_id)
                  LEFT OUTER JOIN prodcat ON (prodcat_id=ipsitem_prodcat_id)
                  LEFT OUTER JOIN uom AS qty ON (qty.uom_id=ipsitem_qty_uom_id)
                  LEFT OUTER JOIN uom AS price ON (price.uom_id=ipsitem_price_uom_id)
+                 LEFT OUTER JOIN itemsite ON (itemsite_item_id=item_id AND itemsite_warehous_id=<? value("warehous_id") ?>)
 WHERE (ipsitem_ipshead_id=<? value("ipshead_id") ?>)
 
 UNION
index 622360f..3ccbf1c 100644 (file)
@@ -2,7 +2,7 @@
 -- Name: populateEdit
 -- Notes: used by enterPoitemReceipt, splitReceipt
 ------PURCHASE ORDER----------
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT pohead_number AS order_number, poitem_linenumber AS orderitem_linenumber,
index 320aaaf..71072b1 100644 (file)
@@ -2,7 +2,7 @@
 -- Name: populateNew
 -- Notes: used by enterPoitemReceipt
 ---------PURCHASE ORDERS-------------
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT pohead_number AS order_number, poitem_linenumber AS orderitem_linenumber,
index 18c5cd3..52ebcc9 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: itemReceipt
 -- Name: sourceItemSite
 -- Notes: used by enterPoitemReceipt
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 <? if exists("poitem_id") ?>                   -- this should never be called
index e4d6e46..2dec020 100644 (file)
@@ -2,7 +2,7 @@
 -- Name: detail
 -- Notes:
 -- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT itemsite_id,warehous_code,itemsite_qtyonhand, itemsite_active, 
index f3caa00..9687c79 100644 (file)
@@ -1,14 +1,17 @@
 -- Group: itemSources
 -- Name: detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
--- See www.xtuple.com/CPAL for the full text of the software license.
-
-SELECT itemsrc_id, 
+--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+--        See www.xtuple.com/CPAL for the full text of the software license.
+<? if not exists("defaultOnly") ?>
+  SELECT itemsrc_id, 
        vend_name, 
        item_number, uom_name,
        (item_descrip1 || ' ' || item_descrip2) AS item_descrip,
        contrct_number,
+       COALESCE( (SELECT SUM(poitem_qty_ordered)
+                  FROM poitem
+                  WHERE (poitem_itemsrc_id=itemsrc_id)), 0.0) AS purchased_qty,
        itemsrc.*,
        'qty' AS itemsrc_invvendoruomratio_xtnumericrole,
        CASE WHEN COALESCE(itemsrc_effective, startOfTime()) <=
@@ -20,38 +23,62 @@ SELECT itemsrc_id,
        CASE WHEN (COALESCE(itemsrc_expires, endOfTime()) < CURRENT_DATE) THEN 'expired'
             WHEN (COALESCE(itemsrc_effective, startOfTime()) > CURRENT_DATE) THEN 'future'
        END AS qtforegroundrole
-FROM itemsrc JOIN vendinfo ON (vend_id=itemsrc_vend_id AND vend_active)
-             JOIN item ON (item_id=itemsrc_item_id)
-             JOIN uom ON (uom_id=item_inv_uom_id)
-             LEFT OUTER JOIN contrct ON (contrct_id=itemsrc_contrct_id) 
-WHERE ((true)
+  FROM itemsrc JOIN vendinfo ON (vend_id=itemsrc_vend_id AND vend_active)
+               JOIN item ON (item_id=itemsrc_item_id)
+               JOIN uom ON (uom_id=item_inv_uom_id)
+               LEFT OUTER JOIN contrct ON (contrct_id=itemsrc_contrct_id) 
+  WHERE ((true)
 <? if not exists("showInactive") ?>
    AND (itemsrc_active)
 <? endif ?>
 <? if exists("item_id") ?>
-  AND (itemsrc_item_id=<? value("item_id") ?>)
+   AND (itemsrc_item_id=<? value("item_id") ?>)
 <? endif ?>
 <? if exists("vend_id") ?>
-  AND (itemsrc_vend_id=<? value("vend_id") ?>)
+   AND (itemsrc_vend_id=<? value("vend_id") ?>)
 <? endif ?>
 <? if exists("contrct_id") ?>
-  AND (itemsrc_contrct_id=<? value("contrct_id") ?>)
+   AND (itemsrc_contrct_id=<? value("contrct_id") ?>)
 <? endif ?>
 <? if exists("contract_number_pattern") ?>
-  AND (contrct_number ~* <? value("contract_number_pattern") ?>)
+   AND (contrct_number ~* <? value("contract_number_pattern") ?>)
 <? endif ?>
 <? if not exists("showExpired") ?>
-  AND (itemsrc_expires > CURRENT_DATE)
+   AND (itemsrc_expires > CURRENT_DATE)
 <? endif ?>
 <? if not exists("showFuture") ?>
-  AND (itemsrc_effective <= CURRENT_DATE)
+   AND (itemsrc_effective <= CURRENT_DATE)
 <? endif ?>
 )
 <? if exists("item_id") ?>
-ORDER BY itemsrc_ranking, vend_name,
+ORDER BY itemsrc_contrct_id, itemsrc_ranking, vend_name,
          itemsrc_vend_item_number, itemsrc_manuf_name,
          itemsrc_manuf_item_number
 <? else ?>
 ORDER By item_number, vend_name
 <? endif ?>
+<? else ?>
+  SELECT itemsrc_id, 0 AS ranked FROM itemsrc, contrct 
+    WHERE ((itemsrc_item_id= <? value("item_id") ?>) AND (itemsrc_default) 
+           AND (contrct_id = itemsrc_contrct_id)) 
+  UNION 
+  SELECT itemsrc_id, 2 AS ranked 
+    FROM itemsrc JOIN (SELECT * FROM 
+                        (SELECT CASE WHEN ((itemsrc_item_id=<? value("item_id") ?>) AND (NOT itemsrc_default)
+                                            AND (contrct_id = itemsrc_contrct_id)) THEN -1
+                                     ELSE itemsrc_id
+                                END AS dummy_id FROM itemsrc, contrct 
+                           WHERE ((itemsrc_item_id=<? value("item_id") ?>) AND (NOT itemsrc_default) 
+                                  AND (contrct_id = itemsrc_contrct_id))
+                         UNION 
+                         SELECT itemsrc_id AS dummy_id 
+                           FROM itemsrc 
+                           WHERE ((itemsrc_item_id=<? value("item_id") ?>) AND (itemsrc_default))
+                         ) AS dummy
+                       LIMIT 1) AS dummy2
+                        ON (itemsrc_id=dummy_id)
+    WHERE ((itemsrc_item_id=<? value("item_id") ?>) AND (itemsrc_default) AND (COALESCE(itemsrc_contrct_id,0)=0))
+
+ORDER by ranked
+<? endif ?>
 ;
index 9e745b6..b94db40 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: itemSources
 -- Name: prices
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT itemsrcp_id, itemsrc_id,
index d35e201..b1a9d20 100644 (file)
@@ -1,8 +1,8 @@
 -- Group: itemSources
 -- Name: search
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
--- See www.xtuple.com/CPAL for the full text of the software license.
+--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+--        See www.xtuple.com/CPAL for the full text of the software license.
 
   SELECT itemsrc_id AS id,
          1 AS altid,
          itemsrc_vend_item_descrip,
          itemsrc_manuf_name,
          itemsrc_manuf_item_number,
-         itemsrc_manuf_item_descrip
+         itemsrc_manuf_item_descrip,
+         contrct_number
     FROM vendinfo JOIN itemsrc ON (itemsrc_vend_id=vend_id)
                   JOIN item ON (item_id=itemsrc_item_id)
+       LEFT OUTER JOIN contrct ON (itemsrc_contrct_id = contrct_id)
    WHERE (vend_id=<? value("vend_id") ?>)
      AND ( (FALSE)
 <? if exists("searchNumber") ?>
@@ -50,7 +52,8 @@
                   poitem_vend_item_descrip,
                   poitem_manuf_name,
                   poitem_manuf_item_number,
-                  poitem_manuf_item_descrip
+                  poitem_manuf_item_descrip,
+                  null AS contrct_id 
     FROM vendinfo JOIN pohead ON (pohead_vend_id=vend_id)
                   JOIN poitem ON (poitem_pohead_id=pohead_id)
                   LEFT OUTER JOIN expcat ON (poitem_expcat_id=expcat_id)
index 3aa2cf4..224d2f6 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: itemcostdetail
 -- Name:  detail
 -- Notes: dspItemCostDetail
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT id, item.item_id, seqnumber, item_number,
index 7d5c3fd..a445444 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: items
 -- Name:  detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
  SELECT
index cf90037..e37114f 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: itemsWithoutItemSources
 -- Name: detail
 -- Notes: used by dspItemsWithoutItemSources
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT item_id, item_number,
index 27dbf1d..36d768e 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: journals
 -- Name:  detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT sltrans.*,
index af0bfd8..3b25e17 100644 (file)
@@ -1,10 +1,11 @@
 -- Group: maintainShipping
 -- Name: detail
 -- Notes: used by maintainShipping
--- order header info
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
--- See www.xtuple.com/CPAL for the full text of the software license.
+--        order header info
+--        Copyright (c) 1999-2013 by OpenMFG LLC, d/b/a xTuple.
+--        See www.xtuple.com/CPAL for the full text of the software license.
 
+-- order header info
 SELECT shiphead_id AS parent_id, cohead_id AS child_id,
        shiphead_number, cohead_number AS linenumber,
        'SO' AS ordertype,
@@ -20,13 +21,15 @@ SELECT shiphead_id AS parent_id, cohead_id AS child_id,
        NULL AS f_shipqty, NULL AS f_shipvalue,
 <? endif ?>
        cohead_holdtype AS holdtype,
+       shiphead_notes AS notes,
        shiphead_number AS shiphead_number_qtdisplayrole,
        'SO' AS ordertype_qtdisplayrole,
        'qty' AS shipqty_xtnumericrole,
        'cost' AS shipvalue_xtnumericrole,
        0 AS shipvalue_xttotalrole,
        0 AS xtindentrole,
-       CAST(shiphead_id AS TEXT) AS sort
+       shiphead_id AS seq1, shiphead_order_id AS seq2,
+       0 AS seq3, 0 AS seq4
 FROM shiphead, custinfo, cohead
  <? if exists("warehous_id") ?>
       JOIN coitem ON (coitem_cohead_id=cohead_id)
@@ -37,12 +40,18 @@ WHERE ((NOT shiphead_shipped)
  AND (shiphead_order_type='SO')
  AND (shiphead_order_id=cohead_id)
  AND (cohead_cust_id=cust_id)
+<? if exists("cust_id") ?>
+ AND (cust_id=<? value("cust_id") ?>)
+<? endif ?>
+<? if exists("cohead_id") ?>
+ AND (cohead_id=<? value("cohead_id") ?>)
+<? endif ?>
 ) 
 -- order line info
 UNION ALL
 SELECT cohead_id AS parent_id, coitem_id AS child_id,
        '' AS shiphead_number, CAST(coitem_linenumber AS TEXT) AS linenumber,
-       'SO' AS ordertype,
+       'SO Item' AS ordertype,
        NULL AS sfstatus,
        item_number AS dest, (item_descrip1 || ' ' || item_descrip2) AS description,
        NULL AS shiphead_shipvia, uom_name,
@@ -53,14 +62,15 @@ SELECT cohead_id AS parent_id, coitem_id AS child_id,
        formatCost(valueAtShipping('SO', coitem_id)) AS f_shipvalue,
 <? endif ?>
        cohead_holdtype AS holdtype,
+       '' as notes,
        NULL AS shiphead_number_qtdisplayrole,
        NULL AS ordertype_qtdisplayrole,
        'qty' AS shipqty_xtnumericrole,
        'cost' AS shipvalue_xtnumericrole,
        0 AS shipvalue_xttotalrole,
        1 AS xtindentrole,
-       CAST(shiphead_id AS TEXT) || CAST(shiphead_order_id AS TEXT) || 
-         TO_CHAR(coitem_id, '0000000') || '1' AS sort
+       shiphead_id AS seq1, shiphead_order_id AS seq2,
+       coitem_id AS seq3, 0 AS seq4
 FROM shiphead, cohead, coitem, uom, itemsite, item
 WHERE ((NOT shiphead_shipped)
  AND (shiphead_order_type='SO')
@@ -72,12 +82,18 @@ WHERE ((NOT shiphead_shipped)
  <? if exists("warehous_id") ?>
  AND (itemsite_warehous_id=<? value("warehous_id") ?>)
  <? endif ?>
+<? if exists("cust_id") ?>
+ AND (cohead_cust_id=<? value("cust_id") ?>)
+<? endif ?>
+<? if exists("cohead_id") ?>
+ AND (cohead_id=<? value("cohead_id") ?>)
+<? endif ?>
 ) 
 -- shipitem info
 UNION ALL
 SELECT shiphead_id AS parent_id, shipitem_id AS child_id,
        '' AS shiphead_number, '' AS linenumber,
-       'SO' AS ordertype,
+       'SO Ship' AS ordertype,
        NULL AS sfstatus,
        '' AS dest,
        formatDate(shipitem_transdate) || ' by ' || shipitem_trans_username AS description,
@@ -89,15 +105,17 @@ SELECT shiphead_id AS parent_id, shipitem_id AS child_id,
        NULL AS f_shipvalue,
 <? endif ?>
        '' AS holdtype,
+       '' AS notes,
        NULL AS shiphead_number_qtdisplayrole,
        NULL AS ordertype_qtdisplayrole,
        'qty' AS shipqty_xtnumericrole,
        'cost' AS shipvalue_xtnumericrole,
        0 AS shipvalue_xttotalrole,
        2 AS xtindentrole,
-       CAST(shiphead_id AS TEXT) || CAST(shiphead_order_id AS TEXT) ||
-         TO_CHAR(shipitem_orderitem_id, '0000000') || '2' AS sort
-FROM shiphead JOIN shipitem ON (shipitem_shiphead_id=shiphead_id)
+       shiphead_id AS seq1, shiphead_order_id AS seq2,
+       shipitem_orderitem_id AS seq3, shipitem_id AS seq4
+FROM shiphead JOIN cohead ON (cohead_id=shiphead_order_id)
+              JOIN shipitem ON (shipitem_shiphead_id=shiphead_id)
  <? if exists("warehous_id") ?>
       JOIN coitem ON ((shipitem_orderitem_id=coitem_id)
                   AND (shiphead_order_type='SO'))
@@ -106,7 +124,59 @@ FROM shiphead JOIN shipitem ON (shipitem_shiphead_id=shiphead_id)
  <? endif ?>
 WHERE ((NOT shiphead_shipped)
  AND (shiphead_order_type='SO')
+<? if exists("cust_id") ?>
+ AND (cohead_cust_id=<? value("cust_id") ?>)
+<? endif ?>
+<? if exists("cohead_id") ?>
+ AND (cohead_id=<? value("cohead_id") ?>)
+<? endif ?>
 ) 
+<? if exists("includeDistributions") ?>
+-- distribution info
+UNION ALL
+SELECT shiphead_id AS parent_id, shipitem_id AS child_id,
+       '' AS shiphead_number, '' AS linenumber,
+       'SO Dist' AS ordertype,
+       NULL AS sfstatus,
+       formatLocationName(invdetail_location_id) AS dest,
+       formatLotSerialNumber(invdetail_ls_id) AS description,
+       formatDate(invdetail_expiration) AS shiphead_shipvia, '' AS uom_name,
+       invdetail_qty AS shipqty,
+       NULL AS shipvalue,
+<? if exists("includeFormatted") ?>
+       formatQty(invdetail_qty) AS f_shipqty,
+       NULL AS f_shipvalue,
+<? endif ?>
+       '' AS holdtype,
+       '' AS notes,
+       NULL AS shiphead_number_qtdisplayrole,
+       NULL AS ordertype_qtdisplayrole,
+       'qty' AS shipqty_xtnumericrole,
+       'cost' AS shipvalue_xtnumericrole,
+       0 AS shipvalue_xttotalrole,
+       3 AS xtindentrole,
+       shiphead_id AS seq1, shiphead_order_id AS seq2,
+       shipitem_orderitem_id AS seq3, shipitem_id AS seq4
+FROM shiphead JOIN cohead ON (cohead_id=shiphead_order_id)
+              JOIN shipitem ON (shipitem_shiphead_id=shiphead_id)
+              LEFT OUTER JOIN invhist ON (invhist_id=shipitem_invhist_id)
+              LEFT OUTER JOIN invdetail ON (invdetail_invhist_id=invhist_id)
+ <? if exists("warehous_id") ?>
+      JOIN coitem ON ((shipitem_orderitem_id=coitem_id)
+                  AND (shiphead_order_type='SO'))
+      JOIN itemsite ON ((coitem_itemsite_id=itemsite_id)
+                    AND (itemsite_warehous_id=<? value("warehous_id") ?>))
+ <? endif ?>
+WHERE ((NOT shiphead_shipped)
+ AND (shiphead_order_type='SO')
+<? if exists("cust_id") ?>
+ AND (cohead_cust_id=<? value("cust_id") ?>)
+<? endif ?>
+<? if exists("cohead_id") ?>
+ AND (cohead_id=<? value("cohead_id") ?>)
+<? endif ?>
+) 
+<? endif ?>
 
 <? if exists("MultiWhs") ?>
 UNION ALL
@@ -126,13 +196,15 @@ SELECT shiphead_id AS parent_id, tohead_id AS child_id,
        NULL AS f_shipqty, NULL AS f_shipvalue,
 <? endif ?>
        'TO' AS holdtype,
+       shiphead_notes AS notes,
        shiphead_number AS shiphead_number_qtdisplayrole,
        'TO' AS ordertype_qtdisplayrole,
        'qty' AS shipqty_xtnumericrole,
        'cost' AS shipvalue_xtnumericrole,
        0 AS shipvalue_xttotalrole,
        0 AS xtindentrole,
-       CAST(shiphead_id AS TEXT) AS sort
+       shiphead_id AS seq1, shiphead_order_id AS seq2,
+       0 AS seq3, 0 AS seq4
 FROM shiphead, tohead
  <? if exists("warehous_id") ?>
       JOIN toitem ON (toitem_tohead_id=tohead_id)
@@ -142,6 +214,12 @@ FROM shiphead, tohead
 WHERE ((NOT shiphead_shipped)
  AND (shiphead_order_type='TO')
  AND (shiphead_order_id=tohead_id)
+<? if exists("cust_id") ?>
+ AND FALSE
+<? endif ?>
+<? if exists("cohead_id") ?>
+ AND FALSE
+<? endif ?>
 ) 
 -- order line info
 UNION ALL
@@ -158,14 +236,15 @@ SELECT tohead_id AS parent_id, toitem_id AS child_id,
        formatCost(valueAtShipping('TO', toitem_id)) AS f_shipvalue,
 <? endif ?>
        'TO' AS holdtype,
+       '' AS notes,
        NULL AS shiphead_number_qtdisplayrole,
        NULL AS ordertype_qtdisplayrole,
        'qty' AS shipqty_xtnumericrole,
        'cost' AS shipvalue_xtnumericrole,
        0 AS shipvalue_xttotalrole,
        1 AS xtindentrole,
-       CAST(shiphead_id AS TEXT) || CAST(shiphead_order_id AS TEXT) ||
-         TO_CHAR(toitem_id, '0000000') || '1' AS sort
+       shiphead_id AS seq1, shiphead_order_id AS seq2,
+       toitem_id AS seq3, 0 AS seq4
 FROM shiphead, tohead, item, toitem
  <? if exists("warehous_id") ?>
       JOIN itemsite ON ((toitem_item_id=itemsite_item_id)
@@ -176,6 +255,12 @@ WHERE ((NOT shiphead_shipped)
  AND (shiphead_order_id=tohead_id)
  AND (tohead_id=toitem_tohead_id)
  AND (toitem_item_id=item_id)
+<? if exists("cust_id") ?>
+ AND FALSE
+<? endif ?>
+<? if exists("cohead_id") ?>
+ AND FALSE
+<? endif ?>
 ) 
 -- shipitem info
 UNION
@@ -193,14 +278,15 @@ SELECT shiphead_id AS parent_id, shipitem_id AS child_id,
        NULL AS f_shipvalue,
 <? endif ?>
        '' AS holdtype,
+       '' AS notes,
        NULL AS shiphead_number_qtdisplayrole,
        NULL AS ordertype_qtdisplayrole,
        'qty' AS shipqty_xtnumericrole,
        'cost' AS shipvalue_xtnumericrole,
        0 AS shipvalue_xttotalrole,
        2 AS xtindentrole,
-       CAST(shiphead_id AS TEXT) || CAST(shiphead_order_id AS TEXT) ||
-         TO_CHAR(shipitem_orderitem_id, '0000000') || '2' AS sort
+       shiphead_id AS seq1, shiphead_order_id AS seq2,
+       shipitem_orderitem_id AS seq3, shipitem_id AS seq4
 FROM shiphead JOIN shipitem ON (shipitem_shiphead_id=shiphead_id)
  <? if exists("warehous_id") ?>
       JOIN toitem ON ((shipitem_orderitem_id=toitem_id)
@@ -210,7 +296,13 @@ FROM shiphead JOIN shipitem ON (shipitem_shiphead_id=shiphead_id)
  <? endif ?>
 WHERE ((NOT shiphead_shipped)
  AND (shiphead_order_type='TO')
+<? if exists("cust_id") ?>
+ AND FALSE
+<? endif ?>
+<? if exists("cohead_id") ?>
+ AND FALSE
+<? endif ?>
 ) 
 
 <? endif ?>
-ORDER BY sort;
+ORDER BY seq1, seq2, seq3, seq4, xtindentrole;
index 3dae7c2..4214c92 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: manufacture
 -- Name: jobcosting
 -- Notes: used by dspJobCosting
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT *, 0 AS cost_xttotalrole,
index 93acfee..3831e02 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: metasqls
 -- Name:  detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 <? if exists('byPackage') ?>
index 7c725da..c4389b9 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: mrpDetail
 -- Name: detail
 -- Notes: used by dspMRPDetail
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT formatQty(itemsite_qtyonhand) AS f_qoh,itemsite_qtyonhand
index e07ef39..d793c54 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: mrpDetail
 -- Name: item
 -- Notes: used by dspMRPDetail
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT itemsite_id, item_type, item_number,
index 2af9e7c..0ea9516 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: openVouchers
 -- Name: populate
 -- Notes: used by openVouchers
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT vohead_id, COALESCE(pohead_id, -1), vohead_number,
index 806e2c5..1e6af03 100644 (file)
 -- Group: openpurchaseorders
 -- Name:  detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
-SELECT pohead_id, COALESCE(pohead_cohead_id, -1) AS pohead_cohead_id,
-                      pohead_number, vend_name,
-                      MIN(poitem_duedate) AS min_duedate, 
-                      pohead_status, pohead_printed,
-                      vend_number, vendtype_code, pohead_agent_username
-               FROM pohead 
-                 JOIN vendinfo ON (pohead_vend_id=vend_id)
-                 JOIN vendtype ON (vend_vendtype_id=vendtype_id)
-               <? if exists("pohead_agent_usr_id") ?>
-                 JOIN usr ON (pohead_agent_username=usr_username)
-               <? endif ?> 
-               <? if exists("warehous_id") ?>
-                 JOIN poitem ON (poitem_pohead_id=pohead_id) 
-                 JOIN itemsite ON (poitem_itemsite_id=itemsite_id)
-               <? else ?>
-                 LEFT OUTER JOIN poitem ON (poitem_pohead_id=pohead_id) 
-               <? endif ?> 
-               WHERE ( true
-               <? if exists("search_pattern") ?> 
-                 AND ((pohead_number::text ~* <? value("search_pattern") ?>) 
-                   OR (vend_number ~* <? value("search_pattern") ?>)
-                   OR (vend_name ~* <? value("search_pattern") ?>)
-
-                   OR (pohead_agent_username ~* <? value("search_pattern") ?>)
-                   OR (vendtype_code ~* <? value("search_pattern") ?>)
-
-                   OR (COALESCE(pohead_vend_cntct_first_name,'') || ' ' || COALESCE(pohead_vend_cntct_last_name,'') ~* <? value("search_pattern") ?>)
-                   OR (COALESCE(pohead_vend_cntct_phone,'') ||' ' || COALESCE(pohead_vend_cntct_fax,'') ~* <? value("search_pattern") ?>)
-                   OR (COALESCE(pohead_vend_cntct_email,'') ~* <? value("search_pattern") ?>)
-                   OR (COALESCE(pohead_vendaddress1,'') || ' ' || COALESCE(pohead_vendaddress2,'') || ' ' || COALESCE(pohead_vendaddress3,'') ~* <? value("search_pattern") ?>)
-                   OR (COALESCE(pohead_vendcity,'') ~* <? value("search_pattern") ?>)
-                   OR (COALESCE(pohead_vendstate,'') ~* <? value("search_pattern") ?>)
-                   OR (COALESCE(pohead_vendzipcode,'') ~* <? value("search_pattern") ?>)
-                   OR (COALESCE(pohead_vendcountry,'') ~* <? value("search_pattern") ?>)
-
-                   OR (COALESCE(pohead_shipto_cntct_first_name,'') || ' ' || COALESCE(pohead_shipto_cntct_last_name,'') ~* <? value("search_pattern") ?>)
-                   OR (COALESCE(pohead_shipto_cntct_phone,'') || ' ' || COALESCE(pohead_shipto_cntct_fax,'') ~* <? value("search_pattern") ?>)
-                   OR (COALESCE(pohead_shipto_cntct_email,'') ~* <? value("search_pattern") ?>)
-                   OR (COALESCE(pohead_shiptoaddress1,'') || ' ' || COALESCE(pohead_vendaddress2,'') || ' ' || COALESCE(pohead_vendaddress3,'') ~* <? value("search_pattern") ?>)
-                   OR (COALESCE(pohead_shiptocity,'') ~* <? value("search_pattern") ?>)
-                   OR (COALESCE(pohead_shiptostate,'') ~* <? value("search_pattern") ?>)
-                   OR (COALESCE(pohead_shiptozipcode,'') ~* <? value("search_pattern") ?>)
-                   OR (COALESCE(pohead_shiptocountry,'') ~* <? value("search_pattern") ?>)
-               )
-               <? endif ?> 
-               <? if exists("showUnreleased") ?> 
-                 AND (pohead_status ='U') 
-               <? endif ?> 
-               <? if exists("showOpen") ?>
-                 AND (pohead_status='O' )
-               <? endif ?> 
-               <? if exists("showBoth") ?> 
-                 AND (pohead_status IN ('U', 'O') ) 
-               <? endif ?> 
-               <? if exists("shownothing") ?> 
-                 AND (pohead_status NOT IN ('U', 'O', 'C')) 
-               <? endif ?> 
-               <? if exists("vend_id") ?>
-                 AND (vend_id=<? value("vend_id") ?>)
-               <? endif ?> 
-               <? if exists("vendtype_id") ?>
-                 AND (vend_vendtype_id=<? value("vendtype_id") ?>)
-               <? endif ?> 
-               <? if exists("vendtype_pattern") ?>
-                 AND (vendtype_code ~* <? value("vendtype_pattern") ?>)
-               <? endif ?> 
-               <? if exists("pohead_agent_usr_id") ?>
-                 AND (usr_id  = <? value("pohead_agent_usr_id") ?>)
-               <? endif ?> 
-               <? if exists("warehous_id") ?>
-                 AND (itemsite_warehous_id = <? value("warehous_id") ?>)
-               <? endif ?> 
-               ) 
-               GROUP BY pohead_number, pohead_id, pohead_cohead_id,
-                vend_name, pohead_status, pohead_printed,
-                        vendtype_code, pohead_agent_username, vend_number
-               ORDER BY pohead_number;
+SELECT DISTINCT
+       pohead_id AS id, COALESCE(pohead_cohead_id, -1) AS altid,
+       pohead.*,
+       calcPurchaseOrderDueDate(pohead_id) AS min_duedate,
+       calcPurchaseOrderAmt(pohead_id) AS order_total,
+       vend_name, vend_number, vendtype_code,
+<? foreach("char_id_text_list") ?>
+       charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>,
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+       charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>,
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+       charass_alias<? literal("char_id_date_list") ?>.charass_value::date AS char<? literal("char_id_date_list") ?>,
+<? endforeach ?>
+       CASE WHEN(pohead_status='C') THEN <? value("closed") ?>
+            WHEN(pohead_status='U') THEN <? value("unposted") ?>
+            WHEN(pohead_status='O') THEN <? value("open") ?>
+            ELSE pohead_status
+       END AS pohead_status_qtdisplayrole,
+       'currency' AS order_total_xtnumericrole
+FROM pohead 
+     JOIN vendinfo ON (pohead_vend_id=vend_id)
+     JOIN vendtype ON (vend_vendtype_id=vendtype_id)
+<? if exists("pohead_agent_usr_id") ?>
+     JOIN usr ON (pohead_agent_username=usr_username)
+<? endif ?> 
+<? if exists("warehous_id") ?>
+     JOIN poitem ON (poitem_pohead_id=pohead_id) 
+     JOIN itemsite ON (poitem_itemsite_id=itemsite_id)
+<? endif ?> 
+<? foreach("char_id_text_list") ?>
+     LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?> 
+          ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='PO') 
+         AND  (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=pohead_id)
+         AND  (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))
+     LEFT OUTER JOIN char char_alias<? literal("char_id_text_list") ?> 
+          ON (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=char_alias<? literal("char_id_text_list") ?>.char_id)
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+     LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?> 
+          ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='PO') 
+         AND  (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=pohead_id)
+         AND  (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))
+     LEFT OUTER JOIN char char_alias<? literal("char_id_list_list") ?> 
+          ON (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=char_alias<? literal("char_id_list_list") ?>.char_id)
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+     LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?> 
+          ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='PO') 
+         AND  (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=pohead_id)
+         AND  (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))
+     LEFT OUTER JOIN char char_alias<? literal("char_id_date_list") ?> 
+          ON (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=char_alias<? literal("char_id_date_list") ?>.char_id)
+<? endforeach ?>
+WHERE ( true
+<? if exists("search_pattern") ?> 
+  AND ((pohead_number::text ~* <? value("search_pattern") ?>) 
+    OR (vend_number ~* <? value("search_pattern") ?>)
+    OR (vend_name ~* <? value("search_pattern") ?>)
+    OR (pohead_agent_username ~* <? value("search_pattern") ?>)
+    OR (vendtype_code ~* <? value("search_pattern") ?>)
+    OR (COALESCE(pohead_vend_cntct_first_name,'') || ' ' || COALESCE(pohead_vend_cntct_last_name,'') ~* <? value("search_pattern") ?>)
+    OR (COALESCE(pohead_vend_cntct_phone,'') ||' ' || COALESCE(pohead_vend_cntct_fax,'') ~* <? value("search_pattern") ?>)
+    OR (COALESCE(pohead_vend_cntct_email,'') ~* <? value("search_pattern") ?>)
+    OR (COALESCE(pohead_vendaddress1,'') || ' ' || COALESCE(pohead_vendaddress2,'') || ' ' || COALESCE(pohead_vendaddress3,'') ~* <? value("search_pattern") ?>)
+    OR (COALESCE(pohead_vendcity,'') ~* <? value("search_pattern") ?>)
+    OR (COALESCE(pohead_vendstate,'') ~* <? value("search_pattern") ?>)
+    OR (COALESCE(pohead_vendzipcode,'') ~* <? value("search_pattern") ?>)
+    OR (COALESCE(pohead_vendcountry,'') ~* <? value("search_pattern") ?>)
+    OR (COALESCE(pohead_shipto_cntct_first_name,'') || ' ' || COALESCE(pohead_shipto_cntct_last_name,'') ~* <? value("search_pattern") ?>)
+    OR (COALESCE(pohead_shipto_cntct_phone,'') || ' ' || COALESCE(pohead_shipto_cntct_fax,'') ~* <? value("search_pattern") ?>)
+    OR (COALESCE(pohead_shipto_cntct_email,'') ~* <? value("search_pattern") ?>)
+    OR (COALESCE(pohead_shiptoaddress1,'') || ' ' || COALESCE(pohead_vendaddress2,'') || ' ' || COALESCE(pohead_vendaddress3,'') ~* <? value("search_pattern") ?>)
+    OR (COALESCE(pohead_shiptocity,'') ~* <? value("search_pattern") ?>)
+    OR (COALESCE(pohead_shiptostate,'') ~* <? value("search_pattern") ?>)
+    OR (COALESCE(pohead_shiptozipcode,'') ~* <? value("search_pattern") ?>)
+    OR (COALESCE(pohead_shiptocountry,'') ~* <? value("search_pattern") ?>)
+    )
+<? endif ?> 
+<? if exists("showUnreleased") ?> 
+  AND (pohead_status ='U') 
+<? endif ?> 
+<? if exists("showOpen") ?>
+  AND (pohead_status='O' )
+<? endif ?> 
+<? if exists("showBoth") ?> 
+  AND (pohead_status IN ('U', 'O') ) 
+<? endif ?> 
+<? if exists("shownothing") ?> 
+  AND (pohead_status NOT IN ('U', 'O', 'C')) 
+<? endif ?> 
+<? if exists("vend_id") ?>
+  AND (vend_id=<? value("vend_id") ?>)
+<? endif ?> 
+<? if exists("vendtype_id") ?>
+  AND (vend_vendtype_id=<? value("vendtype_id") ?>)
+<? endif ?> 
+<? if exists("vendtype_pattern") ?>
+  AND (vendtype_code ~* <? value("vendtype_pattern") ?>)
+<? endif ?> 
+<? if exists("pohead_agent_usr_id") ?>
+  AND (usr_id  = <? value("pohead_agent_usr_id") ?>)
+<? endif ?> 
+<? if exists("warehous_id") ?>
+  AND (itemsite_warehous_id = <? value("warehous_id") ?>)
+<? endif ?> 
+<? literal("charClause") ?>
+ ) 
+ORDER BY pohead_number;
index fb994e0..81385aa 100644 (file)
@@ -1,50 +1,92 @@
 -- Group: opensalesorders
 -- Name:  detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
-SELECT DISTINCT cohead.*,
-                      COALESCE(cust_number, :error) AS cust_number,
-                      getSoSchedDate(cohead_id) AS scheddate, 
-                      getSoStatus(cohead_id) AS status,
-                      firstline(cohead_ordercomments) AS notes 
-                 FROM cohead 
-                   JOIN custinfo ON (cohead_cust_id=cust_id) 
-                   JOIN custtype ON (cust_custtype_id=custtype_id)
-               <? if exists("selectedSites") ?> 
-                   JOIN coitem ON (coitem_cohead_id=cohead_id) 
-                   JOIN itemsite ON (coitem_itemsite_id=itemsite_id) 
-                   JOIN site() ON (itemsite_warehous_id=warehous_id) 
-               <? elseif  exists("warehous_id") ?> 
-                   LEFT OUTER JOIN coitem ON (coitem_cohead_id=cohead_id) 
-                   LEFT OUTER JOIN itemsite ON (coitem_itemsite_id=itemsite_id) 
-                   LEFT OUTER JOIN whsinfo ON (itemsite_warehous_id=warehous_id) 
-                <? endif ?> 
-                WHERE((true) 
-               <? if exists("cust_id") ?>
-                 AND (cust_id=<? value("cust_id") ?> )
-               <? endif ?>
-               <? if exists("custtype_id") ?>
-                 AND (cust_custtype_id=<? value("custtype_id") ?>)
-              <? endif ?>
-              <? if exists("custtype_pattern") ?>
-                 AND (custtype_code ~* <? value("custtype_pattern") ?>)
-              <? endif ?>
-              <? if exists("poNumber") ?>
-                 AND  (cohead_custponumber~*<? value("poNumber") ?>)
-               <? endif ?>
-               <? if exists("startDate") ?>
-                 AND (cohead_orderdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)
-               <? endif ?>
-               <? if not exists("showClosed") ?> 
-                 AND (cohead_status='O')
-               <? endif ?>
-               <? if  exists("warehous_id") ?>
-                 AND (warehous_id=<? value("warehous_id") ?>)
-               <? endif ?>
-               <? if  exists("salesrep_id") ?>
-                 AND (cohead_salesrep_id=<? value("salesrep_id") ?>)
-               <? endif ?>
-                ) 
-               ORDER BY cohead_number;
+SELECT DISTINCT
+       cohead.*,
+       COALESCE(cust_number, :error) AS cust_number,
+       getSoSchedDate(cohead_id) AS scheddate, 
+       getSoStatus(cohead_id) AS status,
+<? foreach("char_id_text_list") ?>
+       charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>,
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+       charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>,
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+       charass_alias<? literal("char_id_date_list") ?>.charass_value::date AS char<? literal("char_id_date_list") ?>,
+<? endforeach ?>
+       firstline(cohead_ordercomments) AS notes,
+       calcSalesOrderAmt(cohead_id) AS ordertotal,
+       CASE WHEN (calcSalesOrderAmt(cohead_id,'S') != 0.0)
+              THEN (calcSalesOrderAmt(cohead_id,'M') / calcSalesOrderAmt(cohead_id,'S'))
+            ELSE 1.0
+       END AS ordermarginpercent,
+       'percent' AS ordermarginpercent_xtnumericrole,
+       'extprice' AS ordertotal_xtnumericrole
+FROM cohead 
+     JOIN custinfo ON (cohead_cust_id=cust_id) 
+     JOIN custtype ON (cust_custtype_id=custtype_id)
+<? if exists("selectedSites") ?> 
+     JOIN coitem ON (coitem_cohead_id=cohead_id) 
+     JOIN itemsite ON (coitem_itemsite_id=itemsite_id) 
+     JOIN site() ON (itemsite_warehous_id=warehous_id) 
+<? elseif  exists("warehous_id") ?> 
+     LEFT OUTER JOIN coitem ON (coitem_cohead_id=cohead_id) 
+     LEFT OUTER JOIN itemsite ON (coitem_itemsite_id=itemsite_id) 
+     LEFT OUTER JOIN whsinfo ON (itemsite_warehous_id=warehous_id) 
+<? endif ?> 
+<? foreach("char_id_text_list") ?>
+     LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?> 
+          ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='SO') 
+         AND  (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=cohead_id)
+         AND  (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))
+     LEFT OUTER JOIN char char_alias<? literal("char_id_text_list") ?> 
+          ON (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=char_alias<? literal("char_id_text_list") ?>.char_id)
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+     LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?> 
+          ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='SO') 
+         AND  (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=cohead_id)
+         AND  (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))
+     LEFT OUTER JOIN char char_alias<? literal("char_id_list_list") ?> 
+          ON (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=char_alias<? literal("char_id_list_list") ?>.char_id)
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+     LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?> 
+          ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='SO') 
+         AND  (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=cohead_id)
+         AND  (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))
+     LEFT OUTER JOIN char char_alias<? literal("char_id_date_list") ?> 
+          ON (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=char_alias<? literal("char_id_date_list") ?>.char_id)
+<? endforeach ?>
+WHERE((true) 
+<? if exists("cust_id") ?>
+  AND (cust_id=<? value("cust_id") ?> )
+<? endif ?>
+<? if exists("custtype_id") ?>
+  AND (cust_custtype_id=<? value("custtype_id") ?>)
+<? endif ?>
+<? if exists("custtype_pattern") ?>
+  AND (custtype_code ~* <? value("custtype_pattern") ?>)
+<? endif ?>
+<? if exists("poNumber") ?>
+  AND  (cohead_custponumber~*<? value("poNumber") ?>)
+<? endif ?>
+<? if exists("startDate") ?>
+  AND (cohead_orderdate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)
+<? endif ?>
+<? if not exists("showClosed") ?> 
+  AND (cohead_status='O')
+<? endif ?>
+<? if  exists("warehous_id") ?>
+  AND (warehous_id=<? value("warehous_id") ?>)
+<? endif ?>
+<? if  exists("salesrep_id") ?>
+  AND (cohead_salesrep_id=<? value("salesrep_id") ?>)
+<? endif ?>
+<? literal("charClause") ?>
+  ) 
+ORDER BY cohead_number;
index eda4935..5db879a 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: opportunities
 -- Name: detail
 -- Notes: used by opportunityList
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT DISTINCT ON (incdtpriority_order, ophead_target_date, ophead_name, ophead_id) 
@@ -23,6 +23,7 @@ SELECT DISTINCT ON (incdtpriority_order, ophead_target_date, ophead_name, ophead
        ophead_target_date,
        ophead_actual_date,
        formatMoney(ophead_amount) AS f_amount,
+       formatMoney(COALESCE(ophead_amount,0) * COALESCE(ophead_probability_prcnt * 0.01)) AS f_value,  
        formatDate(ophead_target_date) AS f_targetdate,
        formatDate(ophead_actual_date) AS f_actualdate,
        'extprice' AS ophead_amount_xtnumericrole,
index b996699..375fed1 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: opportunitiesByCRM
 -- Name: detail
 -- Notes: used by crmaccount
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT ophead_id, *,
index 755a9d6..f211460 100644 (file)
 -- Group: orderActivityByProject
 -- Name:  detail
--- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
--- See www.xtuple.com/CPAL for the full text of the software license.
+-- Notes: All projects
 
 SELECT *, 
   formatQty(qty) AS f_qty,
   formatMoney(value) AS f_value,
   'curr' AS qty_xtnumericrole,
-  'curr' AS value_xtnumericrole
+  'curr' AS value_xtnumericrole,
+  CASE WHEN COALESCE(hrs_balance,0) < 0 THEN 'red' END AS hrs_balance_qtforegroundrole,
+  CASE WHEN COALESCE(exp_balance,0) < 0 THEN 'red' END AS exp_balance_qtforegroundrole
 FROM (
+SELECT prj_id AS id,
+       1 AS type,
+       '0' AS subtype,
+       0 AS section,
+       NULL  AS section_qtdisplayrole,
+       prj_number AS name,
+       CASE                         
+           WHEN prj_status = 'C' THEN <? value('complete') ?>
+           WHEN prj_status = 'O' THEN <? value('inprocess') ?>
+           WHEN prj_status = 'P' THEN <? value('planning') ?>
+       END AS status,
+       prjtype_code AS project_type,
+       prj_name AS item,
+       firstline(prj_descrip) AS descrip,
+       crmacct_name AS customer, 
+       cntct_name AS contact,
+       addr_city AS city,
+       addr_state AS state,
+       NULL::numeric AS qty,
+       NULL::text AS uom,
+       NULL::numeric AS value,
+       prj_due_date AS due,
+       prj_assigned_date AS assigned,
+       prj_start_date AS started,
+       prj_completed_date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+       CASE WHEN (prj_status = 'O' AND prj_due_date < current_date) THEN 'red' 
+         WHEN (prj_status = 'O' AND prj_due_date BETWEEN current_date AND current_date + (fetchmetricvalue('ProjectDueDateWarning')||' days')::interval) THEN 'orange' 
+         END AS due_qtforegroundrole,
+       0 AS xtindentrole
+  FROM prj
+  LEFT OUTER JOIN prjtype ON (prj_prjtype_id=prjtype_id)
+  LEFT OUTER JOIN crmacct ON (prj_crmacct_id=crmacct_id)
+  LEFT OUTER JOIN cntct ON (crmacct_cntct_id_1=cntct_id)
+  LEFT OUTER JOIN addr ON (cntct_addr_id=addr_id)
+
+ WHERE (prj_id = <? value("prj_id") ?> )
+UNION ALL
+----- TASKS -----
+SELECT DISTINCT -1 AS id, 
+       3 AS type,
+       '0' AS subtype,
+       1 AS section,
+       'Tasks' AS section_qtdisplayrole,
+       'Tasks' AS name,
+       NULL::text AS status,
+       NULL::text AS project_type,
+       NULL::text AS item,
+       NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,
+       NULL::numeric AS qty,
+       NULL::text AS uom,
+       NULL::numeric AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       1 AS xtindentrole
+
+UNION ALL
+
+SELECT prjtask_id AS id,
+       5 AS type,
+       '0' AS subtype,
+       1 AS section,
+       NULL AS section_qtdisplayrole,
+       prjtask_number AS name,
+       CASE                         
+           WHEN prjtask_status = 'C' THEN <? value('complete') ?>
+           WHEN prjtask_status = 'O' THEN <? value('inprocess') ?>
+           WHEN prjtask_status = 'P' THEN <? value('planning') ?>
+       END AS status,
+       NULL::text AS project_type,
+       prjtask_name AS item,
+       prjtask_descrip AS descrip,
+       cust_name as customer,
+       cntct_name AS contact,
+       addr_city AS city,
+       addr_state AS state,
+       NULL::numeric AS qty,
+       NULL::text AS uom,
+       NULL::numeric AS value,
+       prjtask_due_date AS due,
+       prjtask_assigned_date AS assigned,
+       prjtask_start_date AS started,
+       prjtask_completed_date AS completed,
+       prjtask_hours_budget AS hrs_budget,
+       prjtask_hours_actual AS hrs_actual,
+       (prjtask_hours_budget-prjtask_hours_actual) AS hrs_balance,
+       prjtask_exp_budget AS exp_budget,
+       prjtask_exp_actual AS exp_actual,
+       (prjtask_exp_budget-prjtask_exp_actual) AS exp_balance,
+       CASE WHEN (prjtask_status = 'O' AND prjtask_due_date < current_date) THEN 'red' 
+         WHEN (prjtask_status = 'O' AND prjtask_due_date BETWEEN current_date AND current_date + (fetchmetricvalue('ProjectDueDateWarning')||' days')::interval) THEN 'orange' 
+         END AS due_qtforegroundrole,
+       2 AS xtindentrole
+  FROM prjtask
+  LEFT OUTER JOIN te.teprjtask ON (prjtask_id = teprjtask_prjtask_id)
+  LEFT OUTER JOIN custinfo ON (teprjtask_cust_id=cust_id)
+  LEFT OUTER JOIN cntct ON (cust_corrcntct_id=cntct_id)
+  LEFT OUTER JOIN addr ON (cntct_addr_id=addr_id)
+
+ WHERE (prjtask_prj_id = <? value("prj_id") ?> )
+ GROUP BY custinfo.cust_name, prjtask.prjtask_id, addr.addr_city, addr.addr_state, cntct_name
+
+<? if exists("showIn") ?>
+UNION ALL
+----- INCIDENTS -----
+
+SELECT DISTINCT -1 AS id, 
+       100 AS type,
+       '0' AS subtype,
+       1 AS section,
+       'Incidents' AS section_qtdisplayrole,
+       'Incidents' AS name,
+       NULL::text AS status,
+       NULL::text AS project_type,
+       NULL::text AS item,
+       NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,
+       NULL::numeric AS qty,
+       NULL::text AS uom,
+       NULL::numeric AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       1 AS xtindentrole
+    FROM incdt
+UNION ALL
+
+SELECT incdt_id AS id,
+       105 AS type,
+       '0' AS subtype,
+       1 AS section,
+       NULL AS section_qtdisplayrole,
+       incdt_number::text AS name,
+       CASE                         
+           WHEN incdt_status = 'L' THEN <? value('closed') ?>
+           WHEN incdt_status = 'N' THEN <? value('new') ?>
+           WHEN incdt_status = 'F' THEN <? value('feedback') ?>
+           WHEN incdt_status = 'A' THEN <? value('assigned') ?>        
+           WHEN incdt_status = 'R' THEN <? value('resolved') ?>
+           WHEN incdt_status = 'C' THEN <? value('confirmed') ?>
+       END AS status,
+       NULL::text AS project_type,
+       incdt_number::text AS item,
+       incdt_summary AS descrip,
+       crmacct_number AS customer,
+       crmacct_name AS contact,
+       addr_city AS city,
+       addr_state AS state,
+       NULL::numeric AS qty,
+       NULL::text AS uom,
+       NULL::numeric AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
+  FROM incdt
+  LEFT OUTER JOIN crmacct ON (incdt_crmacct_id=crmacct_id)
+  LEFT OUTER JOIN cntct ON (incdt_cntct_id=cntct_id)
+  LEFT OUTER JOIN addr ON (cntct_addr_id=addr_id)
+
+ WHERE (incdt_prj_id = <? value("prj_id") ?> )
+ GROUP BY incdt_id, incdt_prj_id, incdt_number, crmacct_number, crmacct_name, addr.addr_city, addr.addr_state, cntct_name, incdt_number, incdt_status, incdt_assigned_username, incdt_owner_username, incdt_number, incdt_summary 
+<? endif ?>
+   
 <? if exists("showSo") ?>
+UNION ALL
+
 ----- QUOTES -----
 SELECT DISTINCT -1 AS id, 
        10 AS type,
@@ -19,12 +225,29 @@ SELECT DISTINCT -1 AS id,
        <? value("quotes") ?> AS section_qtdisplayrole,
        <? value("quotes") ?> AS name,
        NULL::text AS status,
+       NULL::text AS project_type,
        NULL::text AS item,
        NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,
        NULL::numeric AS qty,
        NULL::text AS uom,
-       NULL::numeric AS value,
-       0 AS xtindentrole
+       NULL::numeric AS value, 
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       1 AS xtindentrole
   FROM quhead
 <? if exists("owner_username") ?>
     JOIN prj ON (prj_id=quhead_prj_id
@@ -52,13 +275,31 @@ SELECT quhead_id AS id,
             ELSE
          <? value("expired") ?>
        END AS status,
+       NULL::text AS project_type,
        NULL::text AS item,
        NULL::text AS descrip,
+       cust_name AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
        NULL AS qty,
        NULL::text AS uom,
        NULL AS value,
-       1 AS xtindentrole
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
   FROM quhead
+  JOIN custinfo ON (quhead_cust_id=cust_id)
 <? if exists("owner_username") ?>
     JOIN prj ON (prj_id=quhead_prj_id
             AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))
@@ -68,7 +309,7 @@ SELECT quhead_id AS id,
 <? if exists("owner_username") ?>
    AND (quhead_owner_username=<? value("owner_username") ?>)
 <? endif ?>
-GROUP BY quhead_id, quhead_number, quhead_status, quhead_expire, quhead_freight, quhead_misc
+GROUP BY quhead_id, quhead_number, quhead_status, quhead_expire, quhead_freight, quhead_misc, custinfo.cust_name
 
 UNION ALL
 
@@ -87,12 +328,29 @@ SELECT quitem_id AS id,
             ELSE
          <? value("Expired") ?>
        END AS status,
+       NULL::text AS project_type,
        item_number AS item,
        item_descrip1 || ' ' || item_descrip2 AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
        quitem_qtyord,
        uom_name AS uom,
        (quitem_qtyord * quitem_qty_invuomratio) * (quitem_price / quitem_price_invuomratio) AS value,
-       2 AS xtindentrole
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       3 AS xtindentrole
   FROM quhead
 <? if exists("owner_username") ?>
     JOIN prj ON (prj_id=quhead_prj_id
@@ -116,12 +374,29 @@ SELECT quhead_id AS id,
        <? value("quotes") ?> AS section_qtdisplayrole,
        <? value("total") ?> AS name,
        NULL AS status,
+       NULL::text AS project_type,
        NULL::text AS item,
        NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
        NULL AS qty,
        NULL::text AS uom,
        SUM((quitem_qtyord * quitem_qty_invuomratio) * (quitem_price / quitem_price_invuomratio)) AS value,
-       1 AS xtindentrole
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
   FROM quhead
 <? if exists("owner_username") ?>
     JOIN prj ON (prj_id=quhead_prj_id
@@ -143,12 +418,29 @@ SELECT -1 AS id,
        <? value("quotes") ?> AS section_qtdisplayrole,
        <? value("total") ?> || ' ' || <? value("quotes") ?> AS name,
        NULL AS status,
+       NULL::text AS project_type,
        NULL::text AS item,
        NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
        NULL AS qty,
        NULL::text AS uom,
        SUM((quitem_qtyord * quitem_qty_invuomratio) * (quitem_price / quitem_price_invuomratio)) AS value,
-       1 AS xtindentrole
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
   FROM quhead
 <? if exists("owner_username") ?>
     JOIN prj ON (prj_id=quhead_prj_id
@@ -170,12 +462,29 @@ SELECT DISTINCT -1 AS id,
        <? value("sos") ?> AS section_qtdisplayrole,
        <? value("sos") ?> AS name,
        NULL::text AS status,
+       NULL::text AS project_type,
        NULL::text AS item,
        NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
        NULL::numeric AS qty,
        NULL::text AS uom,
        NULL::numeric AS value,
-       0 AS xtindentrole
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       1 AS xtindentrole
   FROM cohead
 <? if exists("owner_username") ?>
     JOIN prj ON (prj_id=cohead_prj_id
@@ -211,20 +520,39 @@ SELECT cohead_id AS id,
                  ORDER BY type
                  LIMIT 1) AS sts) ,'O')
         AS status,
-       NULL::text AS item,
-       NULL::text AS descrip,
+       NULL::text AS project_type,
+       shipto_num AS item,
+       shipto_name AS descrip,
+       cust_name AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
        NULL AS qty,
        NULL::text AS uom,
        NULL AS value,
-       1 AS xtindentrole
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
   FROM cohead
+    JOIN custinfo ON (cust_id = cohead_cust_id)
+    LEFT OUTER JOIN shiptoinfo ON (cohead_shipto_id = shipto_id)
 <? if exists("owner_username") ?>
     JOIN prj ON (prj_id=cohead_prj_id
             AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))
 <? endif ?>
     JOIN coitem ON (coitem_cohead_id = cohead_id)
  WHERE (cohead_prj_id = <? value("prj_id") ?>)
-GROUP BY cohead_id, cohead_number
+GROUP BY cohead_id, cohead_number, shipto_num, shipto_name, cust_name
 
 UNION ALL
 
@@ -241,12 +569,29 @@ SELECT coitem_id AS id,
             WHEN (coitem_status = 'X') THEN
          <? value("canceled") ?>
        END AS status,
+       NULL::text AS project_type,
        item_number AS item,
        item_descrip1 || ' ' || item_descrip2 AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
        coitem_qtyord,
        uom_name AS uom,
        (coitem_qtyord * coitem_qty_invuomratio) * (coitem_price / coitem_price_invuomratio) AS value,
-       2 AS xtindentrole
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       3 AS xtindentrole
   FROM cohead
 <? if exists("owner_username") ?>
     JOIN prj ON (prj_id=cohead_prj_id
@@ -267,12 +612,29 @@ SELECT cohead_id AS id,
        <? value("sos") ?> AS section_qtdisplayrole,
        <? value("total") ?> AS name,
        NULL AS status,
+       NULL::text AS project_type,
        NULL::text AS item,
        NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
        NULL AS qty,
        NULL::text AS uom,
        SUM((coitem_qtyord * coitem_qty_invuomratio) * (coitem_price / coitem_price_invuomratio)) AS value,
-       1 AS xtindentrole
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
   FROM cohead
 <? if exists("owner_username") ?>
     JOIN prj ON (prj_id=cohead_prj_id
@@ -291,12 +653,29 @@ SELECT -1 AS id,
        <? value("sos") ?> AS section_qtdisplayrole,
        <? value("total") ?> || ' ' || <? value("sos") ?> AS name,
        NULL AS status,
+       NULL::text AS project_type,
        NULL::text AS item,
        NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
        NULL AS qty,
        NULL::text AS uom,
        SUM((coitem_qtyord * coitem_qty_invuomratio) * (coitem_price / coitem_price_invuomratio)) AS value,
-       1 AS xtindentrole
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+               
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
   FROM cohead
 <? if exists("owner_username") ?>
     JOIN prj ON (prj_id=cohead_prj_id
@@ -315,12 +694,29 @@ SELECT DISTINCT -1 AS id,
        <? value("invoices") ?> AS section_qtdisplayrole,
        <? value("invoices") ?> AS name,
        NULL::text AS status,
+       NULL::text AS project_type,
        NULL::text AS item,
        NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
        NULL::numeric AS qty,
        NULL::text AS uom,
        NULL::numeric AS value,
-       0 AS xtindentrole
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       1 AS xtindentrole
   FROM invchead
 <? if exists("owner_username") ?>
     JOIN prj ON (prj_id=invchead_prj_id
@@ -340,20 +736,39 @@ SELECT invchead_id AS id,
          <? value("posted") ?>
        ELSE <? value("unposted") ?>
        END AS status,
-       NULL::text AS item,
-       NULL::text AS descrip,
+       NULL::text AS project_type,
+       shipto_num AS item,
+       shipto_name AS descrip,
+       cust_name AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
        NULL AS qty,
        NULL::text AS uom,
        NULL AS value,
-       1 AS xtindentrole
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
   FROM invchead
+    JOIN custinfo ON (cust_id=invchead_cust_id)
+    LEFT OUTER JOIN shiptoinfo ON (invchead_shipto_id = shipto_id)
 <? if exists("owner_username") ?>
     JOIN prj ON (prj_id=invchead_prj_id
             AND ((prj_owner_username=<? value("owner_username") ?>) OR (prj_username=<? value("owner_username") ?>)))
 <? endif ?>
     JOIN invcitem ON (invcitem_invchead_id = invchead_id)
  WHERE (invchead_prj_id = <? value("prj_id") ?>)
-GROUP BY invchead_id, invchead_invcnumber, invchead_freight, invchead_misc_amount, invchead_posted
+GROUP BY invchead_id, invchead_invcnumber, shipto_num, shipto_name, invchead_freight, invchead_misc_amount, invchead_posted, cust_name
 
 UNION ALL
 
@@ -367,12 +782,29 @@ SELECT invcitem_id AS id,
          <? value("posted") ?>
        ELSE <? value("unposted") ?>
        END AS status,
+       NULL::text AS project_type,
        COALESCE(item_number,invcitem_number) AS item,
        COALESCE(item_descrip1 || ' ' || item_descrip2,invcitem_descrip) AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
        invcitem_billed AS qty,
        uom_name AS uom,
        (invcitem_billed * invcitem_qty_invuomratio) * (invcitem_price / invcitem_price_invuomratio) AS value,
-       2 AS xtindentrole
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       3 AS xtindentrole
   FROM invchead
 <? if exists("owner_username") ?>
     JOIN prj ON (prj_id=invchead_prj_id
@@ -392,12 +824,29 @@ SELECT invchead_id AS id,
        <? value("invoices") ?> AS section_qtdisplayrole,
        <? value("total") ?> AS name,
        NULL AS status,
+       NULL::text AS project_type,
        NULL::text AS item,
        NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
        NULL AS qty,
        NULL::text AS uom,
        SUM((invcitem_billed * invcitem_qty_invuomratio) * (invcitem_price / invcitem_price_invuomratio)) AS value,
-       1 AS xtindentrole
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+       
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
   FROM invchead
 <? if exists("owner_username") ?>
     JOIN prj ON (prj_id=invchead_prj_id
@@ -416,12 +865,29 @@ SELECT -1 AS id,
        <? value("invoices") ?> AS section_qtdisplayrole,
        <? value("total") ?> || ' ' || <? value("invoices") ?> AS name,
        NULL AS status,
+       NULL::text AS project_type,
        NULL::text AS item,
        NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
        NULL AS qty,
        NULL::text AS uom,
        SUM((invcitem_billed * invcitem_qty_invuomratio) * (invcitem_price / invcitem_price_invuomratio)) AS value,
-       1 AS xtindentrole
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
   FROM invchead
 <? if exists("owner_username") ?>
     JOIN prj ON (prj_id=invchead_prj_id
@@ -434,13 +900,8 @@ SELECT -1 AS id,
 
 
 <? if exists("showWo") ?>
-
-<?   if exists("showSo") ?>
-
 UNION ALL
 
-<?   endif ?>
-
 ------ WORK ORDERS -------
 SELECT DISTINCT -1 AS id, 
        40 AS type,
@@ -449,12 +910,29 @@ SELECT DISTINCT -1 AS id,
        <? value("wos") ?> AS section_qtdisplayrole,
        <? value("wos") ?> AS name,
        NULL::text AS status,
+       NULL::text AS project_type,
        NULL::text AS item,
        NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
        NULL::numeric AS qty,
        NULL::text AS uom,
        NULL::numeric AS value,
-       0 AS xtindentrole
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       1 AS xtindentrole
   FROM wo
 <? if exists("owner_username") ?>
     JOIN prj ON (prj_id=wo_prj_id
@@ -481,12 +959,29 @@ SELECT wo_id AS id,
             WHEN (wo_status = 'C') THEN
          <? value("closed") ?>
        END AS status,
+       NULL::text AS project_type,
        item_number AS item,
        item_descrip1 || ' ' || item_descrip2 AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
        wo_qtyord AS qty,
        uom_name AS uom,
        wo_postedvalue AS value,
-       1 AS xtindentrole
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+       
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
   FROM wo
 <? if exists("owner_username") ?>
     JOIN prj ON (prj_id=wo_prj_id
@@ -506,12 +1001,29 @@ SELECT -1 AS id,
        <? value("wos") ?> AS section_qtdisplayrole,
        <? value("total") ?> || ' ' || <? value("wos") ?> AS name,
        NULL AS status,
+       NULL::text AS project_type,
        NULL::text AS item,
        NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
        NULL AS qty,
        NULL::text AS uom,
        SUM(wo_postedvalue) AS value,
-       1 AS xtindentrole
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
   FROM wo
 <? if exists("owner_username") ?>
     JOIN prj ON (prj_id=wo_prj_id
@@ -523,12 +1035,8 @@ SELECT -1 AS id,
 
 
 <? if exists("showPo") ?>
-<?   if exists("showSo") ?>
- UNION ALL
-<? elseif exists("showWo") ?>
  UNION ALL
 
-<? endif ?>
 ------ PURCHASE REQUESTS ------
 SELECT DISTINCT -1 AS id, 
        50 AS type,
@@ -537,12 +1045,29 @@ SELECT DISTINCT -1 AS id,
        <? value("prs") ?> AS section_qtdisplayrole,
        <? value("prs") ?> AS name,
        NULL::text AS status,
+       NULL::text AS project_type,
        NULL::text AS item,
        NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
        NULL::numeric AS qty,
        NULL::text AS uom,
        NULL::numeric AS value,
-       0 AS xtindentrole
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       1 AS xtindentrole
   FROM pr
 <? if exists("owner_username") ?>
     JOIN prj ON (prj_id=pr_prj_id
@@ -559,12 +1084,29 @@ SELECT pr_id AS id,
        <? value("prs") ?> AS section_qtdisplayrole,
        pr_number::text || '-' || pr_subnumber::text AS name,
        <? value("open") ?> AS status, 
+       NULL::text AS project_type,
        item_number AS item,
        (item_descrip1 || ' ' || item_descrip2) AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
        pr_qtyreq AS qty,
        uom_name AS uom,
        stdcost(item_id) * pr_qtyreq AS value,
-       1 AS xtindentrole
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
   FROM pr
 <? if exists("owner_username") ?>
     JOIN prj ON (prj_id=pr_prj_id
@@ -584,12 +1126,29 @@ SELECT -1 AS id,
        <? value("prs") ?> AS section_qtdisplayrole,
        <? value("total") ?> || ' ' || <? value("prs") ?> AS name,
        NULL AS status,
+       NULL::text AS project_type,
        NULL::text AS item,
        NULL::text AS descrip,
+       NULL::text AS customer,       
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
        NULL AS qty,
        NULL::text AS uom,
        SUM(stdcost(item_id) * pr_qtyreq) AS value,
-       1 AS xtindentrole
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
   FROM pr
 <? if exists("owner_username") ?>
     JOIN prj ON (prj_id=pr_prj_id
@@ -609,12 +1168,29 @@ SELECT DISTINCT -1 AS id,
        <? value("pos") ?> AS section_qtdisplayrole,
        <? value("pos") ?> AS name,
        NULL::text AS status,
+       NULL::text AS project_type,
        NULL::text AS item,
        NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
        NULL::numeric AS qty,
        NULL::text AS uom,
        NULL::numeric AS value,
-       0 AS xtindentrole
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       1 AS xtindentrole
   FROM poitem
 <? if exists("owner_username") ?>
     JOIN prj ON (prj_id=poitem_prj_id
@@ -637,12 +1213,29 @@ SELECT pohead_id AS id,
             WHEN (pohead_status = 'C') THEN
          <? value("closed") ?>
        END AS status,
-       NULL::text AS item,
+       NULL::text AS project_type,
+       NULL AS item,
        NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
        NULL AS qty,
        NULL AS uom,
        NULL AS value,
-       1 AS xtindentrole
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
   FROM pohead
     JOIN poitem ON (poitem_pohead_id = pohead_id)
 <? if exists("owner_username") ?>
@@ -667,12 +1260,29 @@ SELECT poitem_id AS id,
             WHEN (poitem_status = 'C') THEN
          <? value("closed") ?>
        END AS status,
+       NULL::text AS project_type,
        COALESCE(item_number,poitem_vend_item_number) AS item,
        COALESCE((item_descrip1 || ' ' || item_descrip2),poitem_vend_item_descrip) AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
        poitem_qty_ordered,
        poitem_vend_uom AS uom,
        (poitem_qty_ordered * poitem_unitprice) AS value,
-       2 AS xtindentrole
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       3 AS xtindentrole
   FROM pohead
     JOIN poitem ON (poitem_pohead_id = pohead_id)
 <? if exists("owner_username") ?>
@@ -692,12 +1302,29 @@ SELECT pohead_id AS id,
        <? value("pos") ?> AS section_qtdisplayrole,
        <? value("total") ?> AS name,
        NULL AS status,
+       NULL::text AS project_type,
        NULL::text AS item,
        NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
        NULL AS qty,
        NULL::text AS uom,
        SUM(poitem_qty_ordered * poitem_unitprice) AS value,
-       1 AS xtindentrole
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
   FROM pohead
     JOIN poitem ON (poitem_pohead_id = pohead_id)
 <? if exists("owner_username") ?>
@@ -716,12 +1343,29 @@ SELECT -1 AS id,
        <? value("sos") ?> AS section_qtdisplayrole,
        <? value("total") ?> || ' ' || <? value("pos") ?> AS name,
        NULL AS status,
+       NULL::text AS project_type,
        NULL::text AS item,
        NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
        NULL AS qty,
        NULL::text AS uom,
        SUM(poitem_qty_ordered * poitem_unitprice) AS value,
-       1 AS xtindentrole
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
   FROM pohead
     JOIN poitem ON (poitem_pohead_id = pohead_id)
 <? if exists("owner_username") ?>
index f4f6c07..7365d06 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: orders
 -- Name: detail
 -- Notes: used by dspOrders
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT source_id, type, order_type, order_status, order_number, duedate,
index 236c8eb..4617ba5 100644 (file)
@@ -4,7 +4,7 @@
 --        and tables so we never miss anything and do not have to maintain the
 --        data
 -- TODO: is there a better sort order?
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT *,
index 1adb25a..f10788c 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: packingList
 -- Name:  getreport
 -- Notes: get the reportname should be used for a packing list or pick list
---        Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 --        See www.xtuple.com/CPAL for the full text of the software license.
 
 <? if exists('sohead_id') ?>
index ad80cdb..f0b3d0b 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: packingList
 -- Name: shipment
 -- Notes: used by printPackingList
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT shiphead_order_id, shiphead_order_type, shiphead_shipform_id, cohead_number AS number
diff --git a/foundation-database/public/tables/metasql/packingListBatch-clear.mql b/foundation-database/public/tables/metasql/packingListBatch-clear.mql
new file mode 100644 (file)
index 0000000..b1cc53d
--- /dev/null
@@ -0,0 +1,32 @@
+-- Group: packingListBatch
+-- Name: clear
+-- Notes: used by packingListBatch
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+-- See www.xtuple.com/CPAL for the full text of the software license.
+
+DELETE FROM pack WHERE pack_id IN
+  (SELECT pack_id
+   FROM pack JOIN cohead ON (cohead_id=pack_head_id)
+             JOIN coitem ON (coitem_cohead_id=cohead_id)
+             JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
+   WHERE ( (checkSOSitePrivs(cohead_id))
+     AND   (pack_head_type='SO')
+     AND   (pack_printed) 
+<? if exists("warehous_id") ?>
+     AND   (itemsite_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
+         )
+  );
+
+<? if exists("MultiWhs") ?>
+DELETE FROM pack WHERE pack_id IN
+  (SELECT pack_id
+   FROM pack JOIN tohead ON (tohead_id=pack_head_id)
+   WHERE ( (pack_head_type='TO')
+     AND   (pack_printed)
+<? if exists("warehous_id") ?>
+     AND   (tohead_src_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
+         )
+  );
+<? endif ?>
index b4a8317..9eaa706 100644 (file)
@@ -1,10 +1,11 @@
 -- Group: packingListBatch
 -- Name: detail
 -- Notes: used by packingListBatch
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
-SELECT cohead_id, pack_shiphead_id, 
+SELECT DISTINCT
+       cohead_id, pack_shiphead_id, 
        cohead_number AS order_number, pack_head_type,
        cohead_shipvia AS shipvia,
        formatShipmentNumber(pack_shiphead_id) AS shipment_number, 
@@ -17,13 +18,19 @@ SELECT cohead_id, pack_shiphead_id,
             ELSE <? value("other") ?>
        END AS f_holdtype,
        pack_printed
-FROM pack, cohead, custinfo
-WHERE pack_head_id=cohead_id 
-  AND  cohead_cust_id=cust_id 
-  AND  pack_head_type='SO' 
+FROM pack JOIN cohead ON (cohead_id=pack_head_id)
+          JOIN custinfo ON (cust_id=cohead_cust_id)
+          JOIN coitem ON (coitem_cohead_id=cohead_id)
+          JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
+WHERE ( (pack_head_type='SO')
+  AND   (checkSOSitePrivs(cohead_id))
+<? if exists("warehous_id") ?>
+  AND   (itemsite_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
+      )
+
 <? if exists("MultiWhs") ?>
-  AND  checkSOSitePrivs(cohead_id)
-UNION 
+UNION ALL 
 SELECT tohead_id, pack_shiphead_id, 
        tohead_number AS order_number, pack_head_type,
        tohead_shipvia AS shipvia,
@@ -31,8 +38,11 @@ SELECT tohead_id, pack_shiphead_id,
        tohead_destname AS number, tohead_destcntct_name AS name,
        '' AS f_holdtype,
        pack_printed
-FROM pack, tohead 
-WHERE ((pack_head_id=tohead_id)
-  AND  (pack_head_type='TO')) 
+FROM pack JOIN tohead ON (tohead_id=pack_head_id) 
+WHERE ( (pack_head_type='TO') 
+<? if exists("warehous_id") ?>
+  AND   (tohead_src_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
+      )
 <? endif ?>
 ORDER BY 3;
index fedb788..dc0a706 100644 (file)
@@ -1,25 +1,37 @@
 -- Group: packingListBatch
 -- Name: print
 -- Notes: used by packingListBatch
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
-SELECT pack_id, pack_head_id, pack_head_type, pack_shiphead_id,
+SELECT DISTINCT
+       pack_id, pack_head_id, pack_head_type, pack_shiphead_id,
        COALESCE(shipform_report_name, findCustomerForm(cohead_cust_id, 'P')) AS packform,
        findCustomerForm(cohead_cust_id, 'L') AS pickform 
 FROM pack JOIN cohead ON (cohead_id=pack_head_id)
+          JOIN coitem ON (coitem_cohead_id=cohead_id)
+          JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
           LEFT OUTER JOIN shipform ON (shipform_id=cohead_shipform_id)
-WHERE ((checkSOSitePrivs(cohead_id))
-  AND  (pack_head_type='SO')
-  AND  (NOT pack_printed) ) 
+WHERE ( (checkSOSitePrivs(cohead_id))
+  AND   (pack_head_type='SO')
+  AND   (NOT pack_printed) 
+<? if exists("warehous_id") ?>
+  AND   (itemsite_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
+      )
+
 <? if exists("MultiWhs") ?>
-UNION 
+UNION ALL
 SELECT pack_id, pack_head_id, pack_head_type, pack_shiphead_id,
        COALESCE(shipform_report_name, findTOForm(tohead_id, 'P')) AS packform,
        findTOForm(tohead_id, 'L') AS pickform 
 FROM pack JOIN tohead ON (tohead_id=pack_head_id)
           LEFT OUTER JOIN shipform ON (shipform_id=tohead_shipform_id)
-WHERE ((pack_head_type='TO')
-  AND  (NOT pack_printed))
+WHERE ( (pack_head_type='TO')
+  AND   (NOT pack_printed)
+<? if exists("warehous_id") ?>
+  AND   (tohead_src_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
+      )
 <? endif ?>
 ;
index c1c66f6..78e6827 100644 (file)
@@ -1,21 +1,28 @@
 -- Group: packingListBatchByShipVia
 -- Name: print
 -- Notes: used by printPackingListBatchByShipVia
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT DISTINCT pack_head_id, pack_head_type, pack_shiphead_id, getSoStatus(cohead_id) AS orderhead_status,
        COALESCE(shipform_report_name, findCustomerForm(cohead_cust_id, 'P')) AS packform,
        findCustomerForm(cohead_cust_id, 'L') AS pickform
 FROM pack JOIN cohead ON (cohead_id=pack_head_id)
-          JOIN coitem ON (coitem_cohead_id = cohead_id) 
+          JOIN coitem ON (coitem_cohead_id=cohead_id)
+          JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
           LEFT OUTER JOIN shipform ON (shipform_id=cohead_shipform_id)
 WHERE ( (NOT pack_printed)
   AND   (pack_head_type='SO')
   AND   (getSoStatus(cohead_id) <> 'C') 
+<? if exists("shipvia") ?>
   AND   (cohead_shipvia=<? value("shipvia") ?>)
+<? endif ?>
   AND   (checkSOSitePrivs(cohead_id))
-  AND  (coitem_scheddate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>) )
+  AND  (coitem_scheddate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)
+<? if exists("warehous_id") ?>
+  AND   (itemsite_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
+      )
 
 <? if exists("MultiWhs") ?>
 UNION ALL
@@ -28,8 +35,14 @@ FROM pack JOIN tohead ON (tohead_id=pack_head_id)
 WHERE ( (NOT pack_printed)
   AND   (pack_head_type='TO')
   AND   (tohead_status <> 'C') 
+<? if exists("shipvia") ?>
   AND   (tohead_shipvia=<? value("shipvia") ?>)
-  AND  (toitem_duedate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>) )
+<? endif ?>
+  AND  (toitem_duedate BETWEEN <? value("startDate") ?> AND <? value("endDate") ?>)
+<? if exists("warehous_id") ?>
+  AND   (tohead_src_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
+      )
 <? endif ?>
 
 ;
index 05906de..7e96760 100644 (file)
@@ -1,28 +1,33 @@
 -- Group: packingListBatchByShipVia
 -- Name: shipVia
 -- Notes: used by printPackingListBatchByShipVia
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 
 SELECT max(id), shipvia
 FROM (
 SELECT max(cohead_id) AS id, cohead_shipvia AS shipvia
-FROM pack, cohead, coitem
+FROM pack JOIN cohead ON (cohead_id=pack_head_id)
+          JOIN coitem ON (coitem_cohead_id=cohead_id AND coitem_status='O')
+          JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
 WHERE ( (NOT pack_printed)
-  AND   (cohead_id=pack_head_id)
   AND   (pack_head_type='SO')
-  AND   (coitem_cohead_id=cohead_id)
-  AND   (coitem_status='O') )
+<? if exists("warehous_id") ?>
+  AND   (itemsite_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
+      )
 GROUP BY cohead_shipvia
 <? if exists("MultiWhs") ?>
 UNION
 SELECT max(tohead_id) AS id, tohead_shipvia AS shipvia
-FROM pack, tohead
+FROM pack JOIN tohead ON (tohead_id=pack_head_id AND tohead_status='O')
 WHERE ( (NOT pack_printed)
-  AND   (tohead_status = 'O')
-  AND   (tohead_id=pack_head_id)
-  AND   (pack_head_type='TO') )
+  AND   (pack_head_type='TO')
+<? if exists("warehous_id") ?>
+  AND   (tohead_src_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
+      )
 GROUP BY tohead_shipvia
 <? endif ?>
 ) data
index 843e958..74fae20 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: partiallyShippedOrders
 -- Name: detail
 -- Notes: used by dspPartiallyShippedOrders
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT CASE WHEN (cohead_holdtype IN ('P', 'C', 'R')) THEN -1
index b335a1a..c68cc92 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: pendingAvailability
 -- Name: detail
 -- Notes: used by dspPendingAvailability
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 <? if exists("showIndented") ?>
index f60d45c..a493fe9 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: pendingBOMChanges
 -- Name: detail
 -- Notes: used by dspPendingBOMChanges
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT bomitem_id, actiondate, action,
index 7f54809..fc560f3 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: poDeliveryDateVariances
 -- Name: detail
 -- Notes: used by dspPoDeliveryDateVariancesByItem, dspPoDeliveryDateVariancesByVendor
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT <? if exists("byItem") ?>
index 9c30b15..9528e0e 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: poHistory
 -- Name: detail
 -- Notes: used by dspPoHistory
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT poitem_id, poitem.*,
index baaf0bf..5436493 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: poItems
 -- Name: detail
 -- Notes: used by dspPoItemsByVendor, dspPoItemsByItem, dspPoItemsByDate
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT pohead_id, poitem_id, pohead_number, poitem_status,
index 47ac0bc..b52853e 100644 (file)
@@ -1,8 +1,8 @@
 -- Group: poItems
 -- Name: list
 -- Notes: used by purchaseOrder
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
--- See www.xtuple.com/CPAL for the full text of the software license.
+--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+--        See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT poitem.*,
        CASE WHEN(poitem_status='C') THEN <? value("closed") ?>
@@ -26,6 +26,7 @@ SELECT poitem.*,
        CASE WHEN (itemsite_id IS NULL) THEN firstLine(poitem_vend_item_descrip)
             ELSE (item_descrip1 || ' ' || item_descrip2)
        END AS item_descrip,
+       contrct_number, 
        poitem_rlsd_duedate AS orgl_duedate,
        (poitem_unitprice * poitem_qty_ordered) AS extprice,
        CASE WHEN(poitem_status='C') THEN <? value("closed") ?>
@@ -50,5 +51,7 @@ FROM pohead JOIN poitem  ON (poitem_pohead_id=pohead_id)
             LEFT OUTER JOIN item     ON (itemsite_item_id=item_id)
             LEFT OUTER JOIN coitem   ON (poitem_order_type='S' AND poitem_order_id = coitem_id)
             LEFT OUTER JOIN womatl   ON (poitem_order_type='W' AND poitem_order_id = womatl_id)
+            LEFT OUTER JOIN itemsrc  ON (poitem_itemsrc_id=itemsrc_id)
+            LEFT OUTER JOIN contrct  ON (itemsrc_contrct_id=contrct_id)
 WHERE (poitem_pohead_id=<? value("pohead_id") ?>)
 ORDER BY poitem_linenumber;
index b9f85ab..12552d1 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: poPriceVariances
 -- Name:  detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT *
index 919ba6c..1ee9a3c 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: poReturns
 -- Name: detail
 -- Notes: used by dspPoReturnsByVendor
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT poreject_id, poreject_ponumber, vend_name,
index fdbb9e1..3bab5d5 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: postCountTags
 -- Name:  post
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT MIN(postCountTag(invcnt_id, <? value('thaw') ?>)) AS result
index d0818c6..9acb254 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: postJournals
 -- Name:  detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT *
index 17a820c..c849988 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: postJournals
 -- Name:  post
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT * 
index 6a0570f..2859c48 100644 (file)
@@ -7,7 +7,7 @@
 --        Then the outer query modifies the sourcecode to indicate
 --        item vs product category.
 --        TODO: possible improvements include removing OUTER JOINs with uom table
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT sourcecode + CASE WHEN source='P' THEN 10 ELSE 0 END AS source,
@@ -47,10 +47,14 @@ FROM (
                 ELSE ipsitem_qtybreak
            END AS invqty,
            ipsitem_qtybreak AS qtybreak,
-           CASE WHEN ipsitem_type = 'N' THEN (ipsitem_price * itemuomtouomratio(<? value('item_id') ?>, NULL, ipsitem_price_uom_id)) *
-                                              iteminvpricerat(ipsitem_item_id)
-                WHEN ipsitem_type = 'D' THEN noNeg(<? value('item_listprice') ?> - (<? value('item_listprice') ?> * ipsitem_discntprcnt) - ipsitem_fixedamtdiscount)
-                WHEN ipsitem_type = 'M' THEN (<? value('item_listcost') ?> + (<? value('item_listcost') ?> * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
+           CASE WHEN (ipsitem_type = 'N') THEN
+                 (ipsitem_price * itemuomtouomratio(<? value('item_id') ?>, NULL, ipsitem_price_uom_id)) * iteminvpricerat(ipsitem_item_id)
+                WHEN (ipsitem_type = 'D') THEN
+                 noNeg(<? value('item_listprice') ?> - (<? value('item_listprice') ?> * ipsitem_discntprcnt) - ipsitem_fixedamtdiscount)
+                WHEN ((ipsitem_type = 'M') AND fetchMetricBool('Long30Markups')) THEN
+                 (<? value('item_unitcost') ?> / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
+                WHEN (ipsitem_type = 'M') THEN
+                 (<? value('item_unitcost') ?> + (<? value('item_unitcost') ?> * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
                 ELSE 0.00
            END AS price,
            ipsitem_qty_uom_id AS qtybreak_uom_id,
@@ -100,7 +104,10 @@ FROM (
            CASE WHEN ipsitem_type = 'N' THEN (ipsitem_price * itemuomtouomratio(<? value('item_id') ?>, NULL, ipsitem_price_uom_id)) *
                                               iteminvpricerat(ipsitem_item_id)
                 WHEN ipsitem_type = 'D' THEN noNeg(<? value('item_listprice') ?> - (<? value('item_listprice') ?> * ipsitem_discntprcnt) - ipsitem_fixedamtdiscount)
-                WHEN ipsitem_type = 'M' THEN (<? value('item_listcost') ?> + (<? value('item_listcost') ?> * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
+                WHEN ((ipsitem_type = 'M') AND fetchMetricBool('Long30Markups')) THEN
+                 (<? value('item_unitcost') ?> / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
+                WHEN (ipsitem_type = 'M') THEN
+                 (<? value('item_unitcost') ?> + (<? value('item_unitcost') ?> * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
                 ELSE 0.00
            END AS price,
            ipsitem_qty_uom_id AS qtybreak_uom_id,
index b84cf3c..769197d 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: prices
 -- Name: detail
 -- Notes: used by dspPricesByCustomerType, dspPricesByCustomer, dspPricesByItem
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT itemid, sourcetype, schedulename, type,
@@ -68,6 +68,9 @@ FROM (
   <? if exists("byCustomer") ?>
          AND (item_price_uom_id=uom_id)
          AND (ipsass_cust_id=<? value("cust_id") ?>)
+         <? if exists("item_id") ?>
+         AND (item_id=<? value("item_id") ?>)
+         <? endif ?>
   <? else ?>
          AND (ipsass_cust_id=cust_id)
          AND (item_id=<? value("item_id") ?>)
@@ -143,6 +146,9 @@ FROM (
 <? elseif exists("byCustomer") ?>
          AND (ipsass_custtype_id=cust_custtype_id)
          AND (cust_id=<? value("cust_id") ?>)
+         <? if exists("item_id") ?>
+         AND (item_id=<? value("item_id") ?>)
+         <? endif ?>
 <? else ?>
          AND (ipsass_custtype_id=custtype_id)
          AND (item_id=<? value("item_id") ?>)
@@ -215,6 +221,9 @@ FROM (
          AND (custtype_id=<? value("custtype_id") ?>)
 <? elseif exists("byCustomer") ?>
          AND (cust_id=<? value("cust_id") ?>)
+         <? if exists("item_id") ?>
+         AND (item_id=<? value("item_id") ?>)
+         <? endif ?>
 <? else ?>
          AND (item_id=<? value("item_id") ?>)
 <? endif ?>
@@ -386,6 +395,9 @@ FROM (
          AND (NOT item_exclusive)
 <? if exists("byCustomer") ?>
          AND (cust_id=<? value("cust_id") ?>)
+         <? if exists("item_id") ?>
+         AND (item_id=<? value("item_id") ?>)
+         <? endif ?>
 <? endif ?>
             )
      ) AS data
index 0b4892b..b630ed8 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: pricingFreight
 -- Name: detail
 -- Notes: used by itemPricingScheduleItem
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT ipsfreight.*
index bf8f7e6..608b3ed 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: projectTasks
 -- Name:  detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2013 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT prjtask_id, prjtask_number, prjtask_name,
index 2e61b7e..9e17bb1 100644 (file)
 -- Group: projects
 -- Name:  detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
--- See www.xtuple.com/CPAL for the full text of the software license.
-
-SELECT prj_id AS id, prj_number, prj_name, prj_descrip,
-  prj_start_date, prj_due_date, prj_assigned_date, prj_completed_date, 
-  CASE WHEN(prj_status='P') THEN <? value("planning") ?>
-       WHEN(prj_status='O') THEN <? value("open") ?>
-       WHEN(prj_status='C') THEN <? value("complete") ?>
-       ELSE <? value("undefined") ?>
-  END AS prj_status, 
-  prj_username, prj_owner_username,
-  crmacct_number, formatCntctName(prj_cntct_id) AS contact_name,
-  COALESCE(SUM(prjtask_hours_budget), 0.0) AS budget_hrs,
-  COALESCE(SUM(prjtask_hours_actual), 0.0) AS actual_hrs,
-  COALESCE(SUM(prjtask_hours_budget - prjtask_hours_actual), 0.0) AS balance_hrs, 
-  CASE WHEN COALESCE(SUM(prjtask_hours_budget - prjtask_hours_actual), 0.0) < 0 THEN 
-  'error' END AS balance_hrs_qtforegroundrole, 
-  'qty' AS budget_hrs_xtnumericrole, 
-  'qty' AS actual_hrs_xtnumericrole, 
-  'qty' AS balance_hrs_xtnumericrole 
-FROM prj()
-  LEFT OUTER JOIN prjtask ON (prj_id=prjtask_prj_id)
-  LEFT OUTER JOIN crmacct ON (crmacct_id=prj_crmacct_id)
+--        Copyright (c) 1999-2013 by OpenMFG LLC, d/b/a xTuple.
+--        See www.xtuple.com/CPAL for the full text of the software license.
+--        
+--        xTuple version 4.2.0 - Modified to significantly amend the display of this screen and its filters.
+--        xTuple version 4.3.0 - Add Incidents to hierarchy display
+SELECT *, 
+  formatQty(qty) AS f_qty,
+  formatMoney(value) AS f_value,
+  'curr' AS qty_xtnumericrole,
+  'curr' AS value_xtnumericrole,
+  CASE WHEN COALESCE(hrs_balance,0) < 0 THEN 'red' END AS hrs_balance_qtforegroundrole,
+  CASE WHEN COALESCE(exp_balance,0) < 0 THEN 'red' END AS exp_balance_qtforegroundrole
+FROM (
+SELECT prj_id AS id,
+       1 AS type,
+       '0' AS subtype,
+       0 AS section,
+       prj_id AS project,
+       NULL  AS section_qtdisplayrole,
+       prj_number AS name,
+       CASE                         
+           WHEN prj_status = 'C' THEN <? value('complete') ?>
+           WHEN prj_status = 'O' THEN <? value('inprocess') ?>
+           WHEN prj_status = 'P' THEN <? value('planning') ?>
+       END AS status,
+       COALESCE(prjtype_descr, 'Undefined') AS project_type,
+       prj_username,
+       prj_owner_username,
+       prj_name AS item,
+       firstline(prj_descrip) AS descrip,
+       crmacct_name AS customer, 
+       cntct_name AS contact,
+       addr_city AS city,
+       addr_state AS state,
+       NULL::numeric AS qty,
+       NULL::text AS uom,
+       NULL::numeric AS value,
+       prj_due_date AS due,
+       prj_assigned_date AS assigned,
+       prj_start_date AS started,
+       prj_completed_date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+       CASE WHEN (prj_status = 'O' AND prj_due_date < current_date) THEN 'red' 
+         WHEN (prj_status = 'O' AND prj_due_date BETWEEN current_date AND current_date + (fetchmetricvalue('ProjectDueDateWarning')||' days')::interval) THEN 'orange' 
+         END AS due_qtforegroundrole,
+       0 AS xtindentrole
+  FROM prj()
+  LEFT OUTER JOIN prjtype ON (prj_prjtype_id=prjtype_id)
+  LEFT OUTER JOIN crmacct ON (prj_crmacct_id=crmacct_id)
+  LEFT OUTER JOIN cntct ON (crmacct_cntct_id_1=cntct_id)
+  LEFT OUTER JOIN addr ON (cntct_addr_id=addr_id)
+
+ WHERE (1=1 )
+UNION ALL
+----- TASKS -----
+SELECT DISTINCT -1 AS id, 
+       3 AS type,
+       '0' AS subtype,
+       1 AS section,
+       prjtask_prj_id AS project,
+       <? value('tasks') ?> AS section_qtdisplayrole,
+       <? value('tasks') ?> AS name,
+       NULL::text AS status,
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       NULL::text AS item,
+       NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,
+       NULL::numeric AS qty,
+       NULL::text AS uom,
+       NULL::numeric AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       1 AS xtindentrole
+    FROM prjtask
+UNION ALL
+
+SELECT prjtask_id AS id,
+       5 AS type,
+       '0' AS subtype,
+       1 AS section,
+       prjtask_prj_id AS project,
+       NULL AS section_qtdisplayrole,
+       prjtask_number AS name,
+       CASE                         
+           WHEN prjtask_status = 'C' THEN <? value('complete') ?>
+           WHEN prjtask_status = 'O' THEN <? value('inprocess') ?>
+           WHEN prjtask_status = 'P' THEN <? value('planning') ?>
+       END AS status,
+       NULL::text AS project_type,
+       prjtask_username AS prj_username,
+       prjtask_owner_username AS prj_owner_username,
+       prjtask_name AS item,
+       prjtask_descrip AS descrip,
+       cust_name as customer,
+       cntct_name AS contact,
+       addr_city AS city,
+       addr_state AS state,
+       NULL::numeric AS qty,
+       NULL::text AS uom,
+       NULL::numeric AS value,
+       prjtask_due_date AS due,
+       prjtask_assigned_date AS assigned,
+       prjtask_start_date AS started,
+       prjtask_completed_date AS completed,
+       prjtask_hours_budget AS hrs_budget,
+       prjtask_hours_actual AS hrs_actual,
+       (prjtask_hours_budget-prjtask_hours_actual) AS hrs_balance,
+       prjtask_exp_budget AS exp_budget,
+       prjtask_exp_actual AS exp_actual,
+       (prjtask_exp_budget-prjtask_exp_actual) AS exp_balance,
+       CASE WHEN (prjtask_status = 'O' AND prjtask_due_date < current_date) THEN 'red' 
+         WHEN (prjtask_status = 'O' AND prjtask_due_date BETWEEN current_date AND current_date + (fetchmetricvalue('ProjectDueDateWarning')||' days')::interval) THEN 'orange' 
+         END AS due_qtforegroundrole,
+       2 AS xtindentrole
+  FROM prjtask
+  LEFT OUTER JOIN te.teprjtask ON (prjtask_id = teprjtask_prjtask_id)
+  LEFT OUTER JOIN custinfo ON (teprjtask_cust_id=cust_id)
+  LEFT OUTER JOIN cntct ON (cust_corrcntct_id=cntct_id)
+  LEFT OUTER JOIN addr ON (cntct_addr_id=addr_id)
+
+ WHERE (1=1 )
+ GROUP BY prjtask_prj_id, custinfo.cust_name, prjtask.prjtask_id, addr.addr_city, addr.addr_state, cntct_name, prjtask.prjtask_number, prjtask.prjtask_status, prjtask_username, prjtask.prjtask_owner_username, prjtask_name, prjtask_descrip, prjtask_due_date, prjtask_assigned_date, prjtask_start_date, prjtask_completed_date, prjtask_hours_budget, prjtask_hours_actual, prjtask_exp_budget, prjtask_exp_actual
+
+<? if exists("showIn") ?>
+
+UNION ALL
+----- INCIDENTS -----
+SELECT DISTINCT -1 AS id, 
+       100 AS type,
+       '0' AS subtype,
+       1 AS section,
+       incdt_prj_id AS project,
+       'Incidents' AS section_qtdisplayrole,
+       'Incidents' AS name,
+       NULL::text AS status,
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       NULL::text AS item,
+       NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,
+       NULL::numeric AS qty,
+       NULL::text AS uom,
+       NULL::numeric AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       1 AS xtindentrole
+    FROM incdt
+UNION ALL
+
+SELECT incdt_id AS id,
+       105 AS type,
+       '0' AS subtype,
+       1 AS section,
+       incdt_prj_id AS project,
+       NULL AS section_qtdisplayrole,
+       incdt_number::text AS name,
+       CASE                         
+           WHEN incdt_status = 'L' THEN <? value('closed') ?>
+           WHEN incdt_status = 'N' THEN <? value('new') ?>
+           WHEN incdt_status = 'F' THEN <? value('feedback') ?>
+           WHEN incdt_status = 'A' THEN <? value('assigned') ?>        
+           WHEN incdt_status = 'R' THEN <? value('resolved') ?>
+           WHEN incdt_status = 'C' THEN <? value('confirmed') ?>
+       END AS status,
+       NULL::text AS project_type,
+       incdt_assigned_username AS prj_username,
+       incdt_owner_username AS prj_owner_username,
+       incdt_number::text AS item,
+       incdt_summary AS descrip,
+       crmacct_number AS customer,
+       crmacct_name AS contact,
+       addr_city AS city,
+       addr_state AS state,
+       NULL::numeric AS qty,
+       NULL::text AS uom,
+       NULL::numeric AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
+  FROM incdt
+  LEFT OUTER JOIN crmacct ON (incdt_crmacct_id=crmacct_id)
+  LEFT OUTER JOIN cntct ON (incdt_cntct_id=cntct_id)
+  LEFT OUTER JOIN addr ON (cntct_addr_id=addr_id)
+
+ WHERE (1=1 )
+ GROUP BY incdt_id, incdt_prj_id, incdt_number, crmacct_number, crmacct_name, addr.addr_city, addr.addr_state, cntct_name, incdt_number, incdt_status, incdt_assigned_username, incdt_owner_username, incdt_number, incdt_summary
+<? endif ?>
+    
+<? if exists("showSo") ?>
+UNION ALL
+
+----- QUOTES -----
+SELECT DISTINCT -1 AS id, 
+       10 AS type,
+       '0' AS subtype,
+       1 AS section,
+       prj_id AS project,
+       <? value("quotes") ?> AS section_qtdisplayrole,
+       <? value("quotes") ?> AS name,
+       NULL::text AS status,
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       NULL::text AS item,
+       NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,
+       NULL::numeric AS qty,
+       NULL::text AS uom,
+       NULL::numeric AS value, 
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       1 AS xtindentrole
+  FROM quhead
+  JOIN prj() ON (quhead_prj_id=prj_id)
+ WHERE (1=1)
+UNION ALL
+
+SELECT quhead_id AS id, 
+       15 AS type,
+       quhead_number AS subtype,
+       1 AS section,
+       prj_id AS project,
+       <? value("quotes") ?> AS section_qtdisplayrole,
+       quhead_number AS name,
+       CASE WHEN (quhead_status = 'C') THEN 
+         <? value("converted") ?>
+            WHEN (quhead_status = 'X') THEN
+         <? value("canceled") ?>
+            WHEN (COALESCE(quhead_expire, current_date + 1) > current_date) THEN
+         <? value("open") ?>
+            ELSE
+         <? value("expired") ?>
+       END AS status,
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       NULL::text AS item,
+       NULL::text AS descrip,
+       cust_name AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
+       NULL AS qty,
+       NULL::text AS uom,
+       NULL AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
+  FROM quhead
+  JOIN prj() ON (quhead_prj_id=prj_id)
+  JOIN custinfo ON (quhead_cust_id=cust_id)
+    JOIN quitem ON (quitem_quhead_id = quhead_id)
+ WHERE (1=1)
+GROUP BY prj_id, quhead_id, quhead_number, quhead_status, quhead_expire, quhead_freight, quhead_misc, custinfo.cust_name
+
+UNION ALL
+
+SELECT quitem_id AS id, 
+       17 AS type,
+       quhead_number AS subtype,
+       1 AS section,
+       prj_id AS project,
+       <? value("quotes") ?> AS section_qtdisplayrole,
+       quitem_linenumber::text AS name, 
+       CASE WHEN (quhead_status = 'C') THEN 
+         <? value("converted") ?>
+            WHEN (quhead_status = 'X') THEN
+         <? value("canceled") ?>
+            WHEN (COALESCE(quhead_expire, current_date + 1) > current_date) THEN
+         <? value("open") ?>
+            ELSE
+         <? value("expired") ?>
+       END AS status,
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       item_number AS item,
+       item_descrip1 || ' ' || item_descrip2 AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
+       quitem_qtyord,
+       uom_name AS uom,
+       (quitem_qtyord * quitem_qty_invuomratio) * (quitem_price / quitem_price_invuomratio) AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance, 
+       NULL::text AS due_qtforegroundrole,
+       3 AS xtindentrole
+  FROM quhead
+  JOIN prj() ON (quhead_prj_id=prj_id)
+    JOIN quitem ON (quitem_quhead_id = quhead_id)
+    JOIN uom ON (quitem_qty_uom_id = uom_id)
+    JOIN itemsite ON (quitem_itemsite_id = itemsite_id)
+    JOIN item ON (itemsite_item_id = item_id)
+ WHERE (1=1)
+
+UNION ALL
+
+SELECT quhead_id AS id, 
+       18 AS type,
+       quhead_number AS subtype,
+       1 AS section,
+       prj_id AS project,
+       <? value("quotes") ?> AS section_qtdisplayrole,
+       <? value("total") ?> AS name,
+       NULL AS status,
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       NULL::text AS item,
+       NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
+       NULL AS qty,
+       NULL::text AS uom,
+       SUM((quitem_qtyord * quitem_qty_invuomratio) * (quitem_price / quitem_price_invuomratio)) AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
+  FROM quhead
+    JOIN prj() ON (quhead_prj_id=prj_id)
+    JOIN quitem ON (quitem_quhead_id = quhead_id)
+ WHERE (1=1)
+GROUP BY prj_id, quhead_id, quhead_number
+
+UNION ALL
+
+SELECT -1 AS id, 
+       19 AS type,
+       MAX(quhead_number) AS subtype,
+       1 AS section,
+       prj_id AS project,
+       <? value("quotes") ?> AS section_qtdisplayrole,
+       <? value("total") ?> || ' ' || <? value("quotes") ?> AS name,
+       NULL AS status,
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       NULL::text AS item,
+       NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
+       NULL AS qty,
+       NULL::text AS uom,
+       SUM((quitem_qtyord * quitem_qty_invuomratio) * (quitem_price / quitem_price_invuomratio)) AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
+  FROM quhead
+    JOIN prj() ON (quhead_prj_id=prj_id)
+    JOIN quitem ON (quitem_quhead_id = quhead_id)
+ WHERE (1=1)
+ GROUP BY prj_id
+
+UNION ALL
+
+------ SALES ORDERS ------
+SELECT DISTINCT -1 AS id, 
+       20 AS type,
+       '0' AS subtype,
+       2 AS section,
+       prj_id AS project,
+       <? value("sos") ?> AS section_qtdisplayrole,
+       <? value("sos") ?> AS name,
+       NULL::text AS status,
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       NULL::text AS item,
+       NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
+       NULL::numeric AS qty,
+       NULL::text AS uom,
+       NULL::numeric AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       1 AS xtindentrole
+  FROM cohead
+    JOIN prj() ON (cohead_prj_id=prj_id)
+ WHERE (1=1)
+
+UNION ALL
+
+SELECT cohead_id AS id, 
+       25 AS type,
+       cohead_number::text AS subtype,
+       2 AS section,
+       prj_id AS project,
+       <? value("sos") ?> AS section_qtdisplayrole,
+       cohead_number::text AS name,
+      COALESCE((SELECT 
+                  CASE WHEN (coitem_status = 'O') THEN
+                    <? value("open") ?>
+                       WHEN (coitem_status = 'C') THEN
+                    <? value("closed" ?>
+                      ELSE
+                    <? value("canceled") ?>
+                  END
+                FROM 
+               (SELECT coitem_status,
+                   CASE 
+                     WHEN (coitem_status = 'O') THEN 1
+                     WHEN (coitem_status = 'C') then 2
+                     ELSE  3
+                  END AS type
+                  FROM coitem
+                 WHERE (coitem_cohead_id=cohead_id)
+                 ORDER BY type
+                 LIMIT 1) AS sts) ,'O')
+        AS status,
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       shipto_num AS item,
+       shipto_name AS descrip,
+       cust_name AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
+       NULL AS qty,
+       NULL::text AS uom,
+       NULL AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
+  FROM cohead
+    JOIN prj() ON (cohead_prj_id=prj_id)
+    JOIN custinfo ON (cust_id = cohead_cust_id)
+    LEFT OUTER JOIN shiptoinfo ON (cohead_shipto_id = shipto_id)
+    JOIN coitem ON (coitem_cohead_id = cohead_id)
+ WHERE (1=1)
+GROUP BY prj_id,cohead_id, cohead_number, shipto_num, shipto_name, cust_name
+
+UNION ALL
+
+SELECT coitem_id AS id, 
+       27 AS type,
+       cohead_number::text AS subtype,
+       2 AS section,
+       prj_id AS project,
+       <? value("sos") ?> AS section_qtdisplayrole,
+       coitem_linenumber::text AS name, 
+       CASE WHEN (coitem_status = 'O') THEN
+         <? value("open") ?>
+            WHEN (coitem_status = 'C') THEN
+         <? value("closed" ?>
+            WHEN (coitem_status = 'X') THEN
+         <? value("canceled") ?>
+       END AS status,
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       item_number AS item,
+       item_descrip1 || ' ' || item_descrip2 AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
+       coitem_qtyord,
+       uom_name AS uom,
+       (coitem_qtyord * coitem_qty_invuomratio) * (coitem_price / coitem_price_invuomratio) AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       3 AS xtindentrole
+  FROM cohead
+    JOIN prj() ON (cohead_prj_id=prj_id)
+    JOIN coitem ON (coitem_cohead_id = cohead_id)
+    JOIN uom ON (coitem_qty_uom_id = uom_id)
+    JOIN itemsite ON (coitem_itemsite_id = itemsite_id)
+    JOIN item ON (itemsite_item_id = item_id)
+ WHERE (1=1)
+
+UNION ALL
+
+SELECT cohead_id AS id, 
+       28 AS type,
+       cohead_number::text AS subtype,
+       2 AS section,
+       prj_id AS project,
+       <? value("sos") ?> AS section_qtdisplayrole,
+       <? value("total") ?> AS name,
+       NULL AS status,
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       NULL::text AS item,
+       NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
+       NULL AS qty,
+       NULL::text AS uom,
+       SUM((coitem_qtyord * coitem_qty_invuomratio) * (coitem_price / coitem_price_invuomratio)) AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
+  FROM cohead
+    JOIN prj() ON (cohead_prj_id=prj_id)
+    JOIN coitem ON (coitem_cohead_id = cohead_id)
+ WHERE (1=1)
+GROUP BY prj_id,cohead_id, cohead_number
+
+UNION ALL
+
+SELECT -1 AS id, 
+       29 AS type,
+       MAX(cohead_number::text) AS subtype,
+       2 AS section,
+       prj_id AS project,
+       <? value("sos") ?> AS section_qtdisplayrole,
+       <? value("total") ?> || ' ' || <? value("sos") ?> AS name,
+       NULL AS status,
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       NULL::text AS item,
+       NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
+       NULL AS qty,
+       NULL::text AS uom,
+       SUM((coitem_qtyord * coitem_qty_invuomratio) * (coitem_price / coitem_price_invuomratio)) AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+               
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
+  FROM cohead
+    JOIN prj() ON (cohead_prj_id=prj_id)
+    JOIN coitem ON (coitem_cohead_id = cohead_id)
+ WHERE (1=1)
+ GROUP BY prj_id
+UNION ALL
+
+------ INVOICES -------
+SELECT DISTINCT -1 AS id, 
+       30 AS type,
+       '0' AS subtype,
+       3 AS section,
+       prj_id AS project,
+       <? value("invoices") ?> AS section_qtdisplayrole,
+       <? value("invoices") ?> AS name,
+       NULL::text AS status,
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       NULL::text AS item,
+       NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
+       NULL::numeric AS qty,
+       NULL::text AS uom,
+       NULL::numeric AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       1 AS xtindentrole
+  FROM invchead
+  JOIN prj() ON (invchead_prj_id=prj_id)
+ WHERE (1=1)
+
+UNION ALL
+
+SELECT invchead_id AS id,
+       35 AS type,
+       invchead_invcnumber::text AS subtype,
+       3 AS section,
+       prj_id AS project,
+       <? value("invoices") ?> AS section_qtdisplayrole,
+       invchead_invcnumber::text AS name,
+       CASE WHEN (invchead_posted) THEN
+         <? value("posted") ?>
+       ELSE <? value("unposted") ?>
+       END AS status,
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       shipto_num AS item,
+       shipto_name AS descrip,
+       cust_name AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
+       NULL AS qty,
+       NULL::text AS uom,
+       NULL AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
+  FROM invchead
+    JOIN prj() ON (invchead_prj_id=prj_id)
+    JOIN custinfo ON (cust_id=invchead_cust_id)
+    LEFT OUTER JOIN shiptoinfo ON (invchead_shipto_id = shipto_id)
+
+    JOIN invcitem ON (invcitem_invchead_id = invchead_id)
+ WHERE (1=1)
+GROUP BY prj_id,invchead_id, invchead_invcnumber, shipto_num, shipto_name, invchead_freight, invchead_misc_amount, invchead_posted, cust_name
+
+UNION ALL
+
+SELECT invcitem_id AS id, 
+       37 AS type,
+       invchead_invcnumber::text AS subtype,
+       3 AS section,
+       prj_id AS project,
+       <? value("invoices") ?> AS section_qtdisplayrole,
+       invcitem_linenumber::text AS name, 
+       CASE WHEN (invchead_posted) THEN
+         <? value("posted") ?>
+       ELSE <? value("unposted") ?>
+       END AS status,
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       COALESCE(item_number,invcitem_number) AS item,
+       COALESCE(item_descrip1 || ' ' || item_descrip2,invcitem_descrip) AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
+       invcitem_billed AS qty,
+       uom_name AS uom,
+       (invcitem_billed * invcitem_qty_invuomratio) * (invcitem_price / invcitem_price_invuomratio) AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       3 AS xtindentrole
+  FROM invchead
+    JOIN prj() ON (invchead_prj_id=prj_id)
+    JOIN invcitem ON (invcitem_invchead_id = invchead_id)
+    LEFT OUTER JOIN item ON (invcitem_item_id = item_id)
+    LEFT OUTER JOIN uom ON (invcitem_qty_uom_id = uom_id)
+ WHERE (1=1)
+
+UNION ALL
+
+SELECT invchead_id AS id, 
+       38 AS type,
+       invchead_invcnumber::text AS subtype,
+       3 AS section,
+       prj_id AS project,
+       <? value("invoices") ?> AS section_qtdisplayrole,
+       <? value("total") ?> AS name,
+       NULL AS status,
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       NULL::text AS item,
+       NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
+       NULL AS qty,
+       NULL::text AS uom,
+       SUM((invcitem_billed * invcitem_qty_invuomratio) * (invcitem_price / invcitem_price_invuomratio)) AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+       
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
+  FROM invchead
+    JOIN prj() ON (invchead_prj_id=prj_id)
+    JOIN invcitem ON (invcitem_invchead_id = invchead_id)
+ WHERE (1=1)
+GROUP BY prj_id,invchead_id, invchead_invcnumber
+
+UNION ALL
+
+SELECT -1 AS id, 
+       39 AS type,
+       MAX(invchead_invcnumber::text) AS subtype,
+       3 AS section,
+       prj_id AS project,
+       <? value("invoices") ?> AS section_qtdisplayrole,
+       <? value("total") ?> || ' ' || <? value("invoices") ?> AS name,
+       NULL AS status,
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       NULL::text AS item,
+       NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
+       NULL AS qty,
+       NULL::text AS uom,
+       SUM((invcitem_billed * invcitem_qty_invuomratio) * (invcitem_price / invcitem_price_invuomratio)) AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
+  FROM invchead
+    JOIN prj() ON (invchead_prj_id=prj_id)
+    JOIN invcitem ON (invcitem_invchead_id = invchead_id)
+ WHERE (1=1)
+ GROUP BY prj_id
+<? endif ?>  
+
+<? if exists("showWo") ?>
+UNION ALL
+
+------ WORK ORDERS -------
+SELECT DISTINCT -1 AS id, 
+       40 AS type,
+       '0' AS subtype,
+       4 AS section,
+       prj_id AS project,
+       <? value("wos") ?> AS section_qtdisplayrole,
+       <? value("wos") ?> AS name,
+       NULL::text AS status,
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       NULL::text AS item,
+       NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
+       NULL::numeric AS qty,
+       NULL::text AS uom,
+       NULL::numeric AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       1 AS xtindentrole
+  FROM wo 
+  JOIN prj() ON (wo_prj_id=prj_id)
+ WHERE (1=1)
+
+UNION ALL
+
+SELECT wo_id AS id, 
+       45 AS type,
+       formatWoNumber(wo_id) AS subtype,
+       4 AS section,
+       prj_id AS project,
+       <? value("wos") ?> AS section_qtdisplayrole,
+       formatWoNumber(wo_id) AS name,
+       CASE WHEN (wo_status = 'O') THEN
+         <? value("open") ?>
+            WHEN (wo_status = 'E') THEN
+         <? value("exploded") ?>
+            WHEN (wo_status = 'R') THEN
+         <? value("released") ?>
+            WHEN (wo_status = 'I') THEN
+         <? value("inprocess") ?>
+            WHEN (wo_status = 'C') THEN
+         <? value("closed" ?>
+       END AS status,
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       item_number AS item,
+       item_descrip1 || ' ' || item_descrip2 AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
+       wo_qtyord AS qty,
+       uom_name AS uom,
+       wo_postedvalue AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+       
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
+  FROM wo
+    JOIN prj() ON (wo_prj_id=prj_id)
+    JOIN itemsite ON (itemsite_id=wo_itemsite_id)
+    JOIN item ON (itemsite_item_id=item_id)
+    JOIN uom ON (item_inv_uom_id=uom_id)
+ WHERE (1=1)
+
+UNION ALL
+
+SELECT -1 AS id, 
+       49 AS type,
+       MAX(formatWoNumber(wo_id)) AS subtype,
+       4 AS section,
+       prj_id AS project,
+       <? value("wos") ?> AS section_qtdisplayrole,
+       <? value("total") ?> || ' ' || <? value("wos") ?> AS name,
+       NULL AS status,
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       NULL::text AS item,
+       NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
+       NULL AS qty,
+       NULL::text AS uom,
+       SUM(wo_postedvalue) AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
+  FROM wo
+     JOIN prj() ON (wo_prj_id=prj_id)
+ WHERE (1=1)
+ GROUP BY prj_id
+
+<? endif ?>
+
+
+<? if exists("showPo") ?>
+ UNION ALL
+------ PURCHASE REQUESTS ------
+SELECT DISTINCT -1 AS id, 
+       50 AS type,
+       '0' AS subtype,
+       5 AS section,
+       prj_id AS project,
+       <? value("prs") ?> AS section_qtdisplayrole,
+       <? value("prs") ?> AS name,
+       NULL::text AS status,
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       NULL::text AS item,
+       NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
+       NULL::numeric AS qty,
+       NULL::text AS uom,
+       NULL::numeric AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       1 AS xtindentrole
+  FROM pr
+    JOIN prj() ON (pr_prj_id=prj_id)
+ WHERE (1=1)
+
+UNION ALL
+
+SELECT pr_id AS id, 
+       55 AS type,
+       pr_number::text || '-' || pr_subnumber::text AS subtype,
+       5 AS section,
+       prj_id AS project,
+       <? value("prs") ?> AS section_qtdisplayrole,
+       pr_number::text || '-' || pr_subnumber::text AS name,
+       <? value("open") ?> AS status, 
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       item_number AS item,
+       (item_descrip1 || ' ' || item_descrip2) AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
+       pr_qtyreq AS qty,
+       uom_name AS uom,
+       stdcost(item_id) * pr_qtyreq AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
+  FROM pr
+    JOIN prj() ON (pr_prj_id=prj_id)
+    JOIN itemsite ON (itemsite_id = pr_itemsite_id)
+    JOIN item ON (itemsite_item_id = item_id)
+    JOIN uom ON (item_inv_uom_id = uom_id)
+ WHERE (1=1)
+
+UNION ALL
+
+SELECT -1 AS id, 
+       59 AS type,
+       MAX(pr_number::text || '-' || pr_subnumber::text) AS subtype,
+       5 AS section,
+       prj_id AS project,
+       <? value("prs") ?> AS section_qtdisplayrole,
+       <? value("total") ?> || ' ' || <? value("prs") ?> AS name,
+       NULL AS status,
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       NULL::text AS item,
+       NULL::text AS descrip,
+       NULL::text AS customer,       
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
+       NULL AS qty,
+       NULL::text AS uom,
+       SUM(stdcost(item_id) * pr_qtyreq) AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
+  FROM pr
+    JOIN prj() ON (pr_prj_id=prj_id)
+    JOIN itemsite ON (itemsite_id = pr_itemsite_id)
+    JOIN item ON (itemsite_item_id = item_id)
+ WHERE (1=1)
+ GROUP BY prj_id
+UNION ALL
+
+------ PURCHASE ORDERS ------
+SELECT DISTINCT -1 AS id, 
+       60 AS type,
+       '0' AS subtype,
+       6 AS section,
+       prj_id AS project,
+       <? value("pos") ?> AS section_qtdisplayrole,
+       <? value("pos") ?> AS name,
+       NULL::text AS status,
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       NULL::text AS item,
+       NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
+       NULL::numeric AS qty,
+       NULL::text AS uom,
+       NULL::numeric AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       1 AS xtindentrole
+  FROM poitem
+    JOIN prj() ON (poitem_prj_id=prj_id)
+ WHERE (1=1)
+
+UNION ALL
+
+SELECT pohead_id AS id,
+       65 AS type,
+       pohead_number::text AS subtype,
+       6 AS section,
+       prj_id AS project,
+       <? value("pos") ?> AS section_qtdisplayrole,
+       pohead_number::text AS name,
+       CASE WHEN (pohead_status = 'U') THEN
+         <? value("unreleased") ?>
+            WHEN (pohead_status = 'O') THEN
+         <? value("open") ?>
+            WHEN (pohead_status = 'C') THEN
+         <? value("closed" ?>
+       END AS status,
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       NULL AS item,
+       NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
+       NULL AS qty,
+       NULL AS uom,
+       NULL AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
+  FROM pohead
+    JOIN poitem ON (poitem_pohead_id = pohead_id)
+    JOIN prj() ON (poitem_prj_id=prj_id)
+ WHERE (1=1)
+GROUP BY prj_id,pohead_id, pohead_number, pohead_freight, pohead_status
+
+UNION ALL
+
+SELECT poitem_id AS id, 
+       67 AS type,
+       pohead_number::text AS subtype,
+       6 AS section,
+       prj_id AS project,
+       <? value("pos") ?> AS section_qtdisplayrole,
+       poitem_linenumber::text AS name, 
+       CASE WHEN (poitem_status = 'U') THEN
+         <? value("unreleased") ?>
+            WHEN (poitem_status = 'O') THEN
+         <? value("open") ?>
+            WHEN (poitem_status = 'C') THEN
+         <? value("closed" ?>
+       END AS status,
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       COALESCE(item_number,poitem_vend_item_number) AS item,
+       COALESCE((item_descrip1 || ' ' || item_descrip2),poitem_vend_item_descrip) AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
+       poitem_qty_ordered,
+       poitem_vend_uom AS uom,
+       (poitem_qty_ordered * poitem_unitprice) AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       3 AS xtindentrole
+  FROM pohead
+    JOIN poitem ON (poitem_pohead_id = pohead_id)
+    JOIN prj() ON (poitem_prj_id=prj_id)
+    LEFT OUTER JOIN itemsite ON (poitem_itemsite_id=itemsite_id)
+    LEFT OUTER JOIN item ON (itemsite_item_id = item_id)
+ WHERE (1=1)
+
+UNION ALL
+
+SELECT pohead_id AS id, 
+       68 AS type,
+       pohead_number::text AS subtype,
+       6 AS section,
+       prj_id AS project,
+       <? value("pos") ?> AS section_qtdisplayrole,
+       <? value("total") ?> AS name,
+       NULL AS status,
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       NULL::text AS item,
+       NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
+       NULL AS qty,
+       NULL::text AS uom,
+       SUM(poitem_qty_ordered * poitem_unitprice) AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
+  FROM pohead
+    JOIN poitem ON (poitem_pohead_id = pohead_id)
+    JOIN prj() ON (poitem_prj_id=prj_id)
+ WHERE (1=1)
+GROUP BY prj_id,pohead_id, pohead_number
+
+UNION ALL
+
+SELECT -1 AS id, 
+       69 AS type,
+       MAX(pohead_number::text) AS subtype,
+       6 AS section,
+       prj_id AS project,
+       'qty' AS section_qtdisplayrole,
+       <? value("total") ?> || ' ' || <? value("pos") ?> AS name,
+       NULL AS status,
+       NULL::text AS project_type,
+       NULL::text AS prj_username,
+       NULL::text AS prj_owner_username,
+       NULL::text AS item,
+       NULL::text AS descrip,
+       NULL::text AS customer,
+       NULL::text AS contact,
+       NULL::text AS city,
+       NULL::text AS state,       
+       NULL AS qty,
+       NULL::text AS uom,
+       SUM(poitem_qty_ordered * poitem_unitprice) AS value,
+       NULL::date AS due,
+       NULL::date AS assigned,
+       NULL::date AS started,
+       NULL::date AS completed,
+       NULL::numeric AS hrs_budget,
+       NULL::numeric AS hrs_actual,
+       NULL::numeric AS hrs_balance,
+       NULL::numeric AS exp_budget,
+       NULL::numeric AS exp_actual,
+       NULL::numeric AS exp_balance,
+        
+       NULL::text AS due_qtforegroundrole,
+       2 AS xtindentrole
+  FROM pohead
+    JOIN poitem ON (poitem_pohead_id = pohead_id)
+    JOIN prj() ON (poitem_prj_id=prj_id)
+ WHERE (1=1)
+ GROUP BY prj_id 
+
+<? endif ?>
+
+) data
+
 WHERE (true)
 <? if exists("search_pattern") ?>
-   AND ( (prj_number ~* <? value("search_pattern") ?>)
+   AND project IN (SELECT prj_id FROM prj WHERE ( (prj_number ~* <? value("search_pattern") ?>)
      OR  (prj_name ~* <? value("search_pattern") ?>)
-     OR  (prj_descrip ~* <? value("search_pattern") ?>) )
+     OR  (prj_descrip ~* <? value("search_pattern") ?>) ))
 <? endif ?>
 <? if exists("username") ?>
   AND (prj_username=<? value("username") ?> OR prj_owner_username=<? value("username") ?>)
@@ -39,47 +1400,64 @@ WHERE (true)
   AND (prj_username ~ <? value("assigned_usr_pattern") ?>) 
 <? endif ?>
 <? if exists("owner_username") ?> 
-  AND (prj_owner_username=<? value("owner_username") ?>) 
+  AND (prj_owner_username=<? value("owner_username") ?>)
 <? elseif exists("owner_usr_pattern") ?>
   AND (prj_owner_username ~ <? value("owner_usr_pattern") ?>) 
 <? endif ?>
 <? if exists("crmacct_id") ?>
-  AND (prj_crmacct_id=<? value("crmacct_id") ?>)
+  AND project IN (SELECT prj_id FROM prj WHERE (prj_crmacct_id=<? value("crmacct_id") ?>))
 <? endif ?>
 <? if exists("cntct_id") ?>
-  AND (prj_cntct_id=<? value("cntct_id") ?>)
+  AND project IN (SELECT prj_id FROM prj WHERE (prj_cntct_id=<? value("cntct_id") ?>))
 <? endif ?>
 <? if exists("startStartDate") ?>
-  AND (prj_start_date >= <? value("startStartDate") ?>)
+  AND project IN (SELECT prj_id FROM prj WHERE (prj_start_date >= <? value("startStartDate") ?>))
 <? endif ?>
 <? if exists("startEndDate") ?>
-  AND (prj_start_date <= <? value("startEndDate") ?>)
+  AND project IN (SELECT prj_id FROM prj WHERE (prj_start_date <= <? value("startEndDate") ?>))
 <? endif ?>
 <? if exists("dueStartDate") ?>
-  AND (prj_due_date >= <? value("dueStartDate") ?>)
+  AND project IN (SELECT prj_id FROM prj WHERE (prj_due_date >= <? value("dueStartDate") ?>))
 <? endif ?>
 <? if exists("dueEndDate") ?>
-  AND (prj_due_date <= <? value("dueEndDate") ?>)
+  AND project IN (SELECT prj_id FROM prj WHERE (prj_due_date <= <? value("dueEndDate") ?>))
 <? endif ?>
 <? if exists("assignedStartDate") ?>
-  AND (prj_assigned_date >= <? value("assignedStartDate") ?>)
+  AND project IN (SELECT prj_id FROM prj WHERE (prj_assigned_date >= <? value("assignedStartDate") ?>))
 <? endif ?>
 <? if exists("assignedEndDate") ?>
-  AND (prj_assigned_date <= <? value("assignedEndDate") ?>)
+  AND project IN (SELECT prj_id FROM prj WHERE (prj_assigned_date <= <? value("assignedEndDate") ?>))
 <? endif ?>
 <? if exists("completedStartDate") ?>
-  AND (prj_completed_date >= <? value("completedStartDate") ?>)
+  AND project IN (SELECT prj_id FROM prj WHERE (prj_completed_date >= <? value("completedStartDate") ?>))
 <? endif ?>
 <? if exists("completedEndDate") ?>
-  AND (prj_completed_date <= <? value("completedEndDate") ?>)
+  AND project IN (SELECT prj_id FROM prj WHERE (prj_completed_date <= <? value("completedEndDate") ?>))
 <? endif ?>
 <? if not exists("showComplete") ?>
-  AND (prj_status <> 'C')
+  AND project IN (SELECT prj_id FROM prj WHERE prj_status <> 'C')
+<? endif ?>
+<? if exists("prj_id") ?>
+  AND (project=<? value("prj_id") ?>)
+<? endif ?>
+<? if exists("prjtype_id") ?>
+  AND project IN (SELECT prj_id FROM prj WHERE (prj_prjtype_id=<? value("prjtype_id") ?>))
+<? endif ?>
+<? if exists("project_task") ?>
+  AND project IN (SELECT DISTINCT prjtask_prj_id FROM prjtask where ((prjtask_number ~* <? value("project_task") ?>)
+                                               OR (prjtask_name ~* <? value("project_task") ?>)
+                                               OR (prjtask_descrip ~* <? value("project_task") ?>)))
 <? endif ?>
-<? if exists("id") ?>
-  AND (prj_id=<? value("id") ?>)
+<? if exists("cohead_id") ?>
+  AND project IN (SELECT cohead_prj_id FROM cohead where cohead_id=<? value("cohead_id") ?>)
 <? endif ?>
-GROUP BY prj_id, prj_number, prj_name, prj_descrip, prj_status, prj_username, prj_owner_username,
-  crmacct_number, prj_cntct_id,
-  prj_start_date, prj_due_date, prj_assigned_date, prj_completed_date
-ORDER BY prj_number;
+<? if exists("wo_id") ?>
+  AND project IN (SELECT wo_prj_id FROM wo WHERE wo_id=<? value("wo_id") ?>)
+<? endif ?>
+<? if exists("pohead_id") ?>
+  AND project IN (SELECT poitem_prj_id FROM pohead JOIN poitem ON (pohead_id=poitem_pohead_id) 
+                       WHERE pohead_id=<? value("pohead_id") ?>)
+<? endif ?>
+
+
+ORDER BY project, section, subtype, type, id;
diff --git a/foundation-database/public/tables/metasql/projects-detail_nohierarchy.mql b/foundation-database/public/tables/metasql/projects-detail_nohierarchy.mql
new file mode 100644 (file)
index 0000000..cb75d4c
--- /dev/null
@@ -0,0 +1,104 @@
+-- Group: projects
+-- Name:  detail_nohierarchy
+-- Notes: Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+--        See www.xtuple.com/CPAL for the full text of the software license.
+--        
+--        Non-hierarchical view to support CSV export from Project List screen
+
+SELECT prj_id AS id, 1 AS altId,
+  prj.*, crmacct_name, cntct_name,
+  addr_city, addr_state,
+  prjtype_descr AS project_type,
+  CASE WHEN (prj_status='P') THEN 'Planning'
+       WHEN (prj_status='O') THEN 'In-Process'
+       WHEN (prj_status='C') THEN 'Completed'
+       ELSE 'Unknown' END AS project_status
+<? foreach("char_id_text_list") ?>
+  , charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+  , charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+  , charass_alias<? literal("char_id_date_list") ?>.charass_value::date AS char<? literal("char_id_date_list") ?>
+<? endforeach ?>
+FROM prj() 
+LEFT JOIN prjtype ON (prj_prjtype_id=prjtype_id)
+LEFT JOIN crmacct ON (prj_crmacct_id=crmacct_id)
+LEFT JOIN cntct ON (crmacct_cntct_id_1=cntct_id)
+LEFT JOIN addr ON (cntct_addr_id=addr_id)
+<? foreach("char_id_text_list") ?>
+  LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?> ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='PROJ') 
+                                                                    AND  (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=prj_id)
+                                                                    AND  (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))
+  LEFT OUTER JOIN char char_alias<? literal("char_id_text_list") ?> ON (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=char_alias<? literal("char_id_text_list") ?>.char_id)
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+  LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?> ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='PROJ') 
+                                                                    AND  (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=prj_id)
+                                                                    AND  (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))
+  LEFT OUTER JOIN char char_alias<? literal("char_id_list_list") ?> ON (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=char_alias<? literal("char_id_list_list") ?>.char_id)
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+  LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?> ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='PROJ') 
+                                                                    AND  (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=prj_id)
+                                                                    AND  (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))
+  LEFT OUTER JOIN char char_alias<? literal("char_id_date_list") ?> ON (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=char_alias<? literal("char_id_date_list") ?>.char_id)
+<? endforeach ?>
+WHERE (true)
+<? if exists("search_pattern") ?>
+   AND ( (prj_number ~* <? value("search_pattern") ?>)
+     OR  (prj_name ~* <? value("search_pattern") ?>)
+     OR  (prj_descrip ~* <? value("search_pattern") ?>) )
+<? endif ?>
+<? if exists("username") ?>
+  AND (prj_username=<? value("username") ?> OR prj_owner_username=<? value("username") ?>)
+<? endif ?>
+<? if exists("assigned_username") ?> 
+  AND (prj_username=<? value("assigned_username") ?>) 
+<? elseif exists("assigned_usr_pattern") ?>
+  AND (prj_username ~ <? value("assigned_usr_pattern") ?>) 
+<? endif ?>
+<? if exists("owner_username") ?> 
+  AND (prj_owner_username=<? value("owner_username") ?>) 
+<? elseif exists("owner_usr_pattern") ?>
+  AND (prj_owner_username ~ <? value("owner_usr_pattern") ?>) 
+<? endif ?>
+<? if exists("crmacct_id") ?>
+  AND (prj_crmacct_id=<? value("crmacct_id") ?>)
+<? endif ?>
+<? if exists("cntct_id") ?>
+  AND (prj_cntct_id=<? value("cntct_id") ?>)
+<? endif ?>
+<? if exists("startStartDate") ?>
+  AND (prj_start_date >= <? value("startStartDate") ?>)
+<? endif ?>
+<? if exists("startEndDate") ?>
+  AND (prj_start_date <= <? value("startEndDate") ?>)
+<? endif ?>
+<? if exists("dueStartDate") ?>
+  AND (prj_due_date >= <? value("dueStartDate") ?>)
+<? endif ?>
+<? if exists("dueEndDate") ?>
+  AND (prj_due_date <= <? value("dueEndDate") ?>)
+<? endif ?>
+<? if exists("assignedStartDate") ?>
+  AND (prj_assigned_date >= <? value("assignedStartDate") ?>)
+<? endif ?>
+<? if exists("assignedEndDate") ?>
+  AND (prj_assigned_date <= <? value("assignedEndDate") ?>)
+<? endif ?>
+<? if exists("completedStartDate") ?>
+  AND (prj_completed_date >= <? value("completedStartDate") ?>)
+<? endif ?>
+<? if exists("completedEndDate") ?>
+  AND (prj_completed_date <= <? value("completedEndDate") ?>)
+<? endif ?>
+<? if not exists("showComplete") ?>
+  AND (prj_status <> 'C')
+<? endif ?>
+<? if exists("id") ?>
+  AND (prj_id=<? value("id") ?>)
+<? endif ?>
+<? literal("charClause") ?>
+ORDER BY prj_number;
index 52529b3..3d4eafa 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: prospects
 -- Name:  detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT 
index baa4f32..840c413 100644 (file)
@@ -1,11 +1,11 @@
 -- Group: purchase
 -- Name:  purchaserequests
 -- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
-SELECT pr_id, itemsite_id, item_number,
-       (item_descrip1 || ' ' || item_descrip2) AS description,
+SELECT pr_id, itemsite_id, itemsite_qtyonhand, itemsite_reorderlevel,
+       item_number, (item_descrip1 || ' ' || item_descrip2) AS description,
        pr.*,
        CASE WHEN (pr_order_type='W') THEN ('W/O ' || ( SELECT formatWoNumber(womatl_wo_id)
                                                        FROM womatl
@@ -15,6 +15,8 @@ SELECT pr_id, itemsite_id, item_number,
             WHEN (pr_order_type='M') THEN <? value("manual") ?>
             ELSE <? value("other") ?>
        END AS parent,
+       'qty' AS itemsite_qtyonhand_xtnumericrole, 
+       'qty' AS itemsite_reorderlevel_xtnumericrole,
        'qty' AS pr_qtyreq_xtnumericrole 
 FROM pr, itemsite, item 
 WHERE ((pr_itemsite_id=itemsite_id)
index acfb1bd..71d4f1a 100644 (file)
@@ -1,8 +1,8 @@
 -- Group: purchaseOrderItems
 -- Name: detail
 -- Notes: used by purchaseOrderItem
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
--- See www.xtuple.com/CPAL for the full text of the software license.
+--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+--        See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT pohead_number, pohead_taxzone_id,
        pohead_curr_id, pohead_orderdate,
@@ -31,11 +31,13 @@ SELECT pohead_number, pohead_taxzone_id,
        END AS order_number,
        poitem_unitprice * poitem_qty_ordered AS extended_price,
        COALESCE(coitem_prcost, 0.0) AS override_cost,
+       contrct_number,
        itemsrc.*
   FROM poitem JOIN pohead ON (pohead_id=poitem_pohead_id)
               LEFT OUTER JOIN itemsrc ON (itemsrc_id=poitem_itemsrc_id)
               LEFT OUTER JOIN coitem  ON (poitem_order_type='S' AND coitem_id=poitem_order_id)
               LEFT OUTER JOIN womatl  ON (poitem_order_type='W' AND womatl_id=poitem_order_id)
+              LEFT OUTER JOIN contrct ON (itemsrc_contrct_id=contrct_id)
  WHERE ( (TRUE)
 <? if exists("poitem_id") ?>
    AND (poitem_id=<? value("poitem_id") ?>)
index 9d27d17..79ae3ac 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: purchaseOrders
 -- Name: detail
 -- Notes: used by dspPosByVendor, dspPOsByDate
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT pohead_id, pohead_number,
index dc08446..cd80d69 100644 (file)
@@ -2,18 +2,18 @@
 -- Name: detail
 -- Notes: 
 -- Quantity on Hand By Location
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 <? if exists("byLocation") ?>
-SELECT itemloc_id, warehous_code, item_number,
+SELECT itemloc_id, alt_id, warehous_code, item_number,
        f_descrip, f_lotserial, uom_name,
        qoh, reservedqty,
        'qty' AS qoh_xtnumericrole,
        'qty' AS reservedqty_xtnumericrole,
        level AS xtindentrole
 FROM (
-      SELECT itemloc_id, 0 AS level, item_number AS sortkey, warehous_code, item_number,
+      SELECT itemloc_id, 0 AS alt_id, 0 AS level, item_number AS sortkey, warehous_code, item_number,
              (item_descrip1 || ' ' || item_descrip2) AS f_descrip,
              formatlotserialnumber(itemloc_ls_id) AS f_lotserial, uom_name,
              itemloc_qty AS qoh,
@@ -29,7 +29,7 @@ FROM (
          AND (itemsite_warehous_id=warehous_id)
          AND (itemloc_location_id=<? value("location_id") ?>))
       UNION
-      SELECT -1 AS itemloc_id, 0 AS level, item_number AS sortkey, warehous_code, item_number,
+      SELECT -1 AS itemloc_id, 0 AS alt_id, 0 AS level, item_number AS sortkey, warehous_code, item_number,
              (item_descrip1 || ' ' || item_descrip2) AS f_descrip,
              <? value("na") ?> AS f_lotserial, uom_name,
              itemsite_qtyonhand AS qoh,
@@ -42,16 +42,53 @@ FROM (
          AND (itemsite_location_id=<? value("location_id") ?>))
   <? if exists("EnableSOReservationsByLocation") ?>
       UNION
-      SELECT itemloc_id, 1 AS level, item_number AS sortkey, '' AS warehous_code, '' AS item_number,
-             (itemlocrsrv_source || '-' || formatSOItemNumber(itemlocrsrv_source_id)) AS f_descrip,
+      SELECT itemloc_id, -1 AS alt_id, 1 AS level, item_number AS sortkey, '' AS warehous_code, '' AS item_number,
+             (reserve_demand_type || '-' || formatSOItemNumber(reserve_demand_id)) AS f_descrip,
              '' AS f_lotserial, '' AS uom_name,
              NULL AS qoh,
-             itemlocrsrv_qty AS reservedqty
-      FROM itemlocrsrv, itemloc, itemsite, item
-      WHERE ((itemlocrsrv_itemloc_id=itemloc_id)
+             reserve_qty AS reservedqty
+      FROM reserve, itemloc, itemsite, item
+      WHERE ((reserve_supply_id=itemloc_id)
+         AND (reserve_supply_type='I')
          AND (itemsite_id=itemloc_itemsite_id)
          AND(item_id=itemsite_item_id)
          AND(itemloc_location_id=<? value("location_id") ?>))
+  <? endif ?>
+  <? if exists("ShowDemand") ?>
+      UNION
+      SELECT itemloc_id, coitem_cohead_id AS alt_id, 1 AS level, item_number AS sortkey, '' AS warehous_code, '' AS item_number,
+             (<? value("so") ?>|| '-' || formatSOItemNumber(coitem_id)) AS f_descrip,
+             '' AS f_lotserial, '' AS uom_name,
+             itemUOMtoUOM(item_id, coitem_qty_uom_id, NULL, (coitem_qtyord - coitem_qtyshipped - qtyAtShipping(coitem_id))) AS qoh,
+             0 AS reservedqty
+      FROM itemloc JOIN itemsite ON (itemsite_id=itemloc_itemsite_id)
+                   JOIN item ON (item_id=itemsite_item_id)
+                   JOIN coitem ON (coitem_itemsite_id=itemloc_itemsite_id AND coitem_status='O')
+      WHERE ((coitem_qtyord > (coitem_qtyshipped + qtyAtShipping(coitem_id)))
+         AND(itemloc_location_id=<? value("location_id") ?>))
+      UNION
+      SELECT itemloc_id, -1 AS alt_id, 1 AS level, item_number AS sortkey, '' AS warehous_code, '' AS item_number,
+             (<? value("wo") ?>|| '-' || formatWONumber(womatl_wo_id)) AS f_descrip,
+             '' AS f_lotserial, '' AS uom_name,
+             (womatl_qtyreq - womatl_qtyiss) AS qoh,
+             0 AS reservedqty
+      FROM itemloc JOIN itemsite ON (itemsite_id=itemloc_itemsite_id)
+                   JOIN item ON (item_id=itemsite_item_id)
+                   JOIN womatl ON (womatl_itemsite_id=itemloc_itemsite_id)
+      WHERE ((womatl_qtyreq > womatl_qtyiss)
+         AND(itemloc_location_id=<? value("location_id") ?>))
+      UNION
+      SELECT itemloc_id, -1 AS alt_id, 1 AS level, item_number AS sortkey, '' AS warehous_code, '' AS item_number,
+             (<? value("to") ?>|| '-' || formatTONumber(toitem_id)) AS f_descrip,
+             '' AS f_lotserial, '' AS uom_name,
+             (toitem_qty_ordered - toitem_qty_shipped - qtyAtShipping('TO', toitem_id)) AS qoh,
+             0 AS reservedqty
+      FROM itemloc JOIN itemsite ON (itemsite_id=itemloc_itemsite_id)
+                   JOIN item ON (item_id=itemsite_item_id)
+                   JOIN toitem ON (toitem_item_id=item_id AND toitem_status='O')
+                   JOIN tohead ON (tohead_id=toitem_tohead_id AND tohead_src_warehous_id=itemsite_warehous_id)
+      WHERE ((toitem_qty_ordered > (toitem_qty_shipped + qtyAtShipping('TO', toitem_id)))
+         AND(itemloc_location_id=<? value("location_id") ?>))
   <? endif ?>
      ) AS data
 ORDER BY
index 9c06b89..a21178a 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: quoteItems
 -- Name: detail
 -- Notes: used by dspQuotesByItem
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT quitem_id, quhead_id,
diff --git a/foundation-database/public/tables/metasql/quoteItems-list.mql b/foundation-database/public/tables/metasql/quoteItems-list.mql
new file mode 100644 (file)
index 0000000..f253f7c
--- /dev/null
@@ -0,0 +1,54 @@
+-- Group: quoteItems
+-- Name: list
+-- Notes: used by salesOrder
+--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+--        See www.xtuple.com/CPAL for the full text of the software license.
+
+SELECT quitem_id,
+       quitem_linenumber AS f_linenumber,
+       0 AS coitem_subnumber, item_type,
+       item_number, (item_descrip1 || ' ' || item_descrip2) AS description,
+       warehous_code, '' AS enhanced_status,
+       quitem_scheddate AS coitem_scheddate,
+       quom.uom_name AS qty_uom,
+       quitem_qtyord AS coitem_qtyord,
+       0 AS qtyshipped, 0 AS qtyatshipping, 0 AS balance,
+       puom.uom_name AS price_uom,
+       quitem_price AS coitem_price,
+       ROUND((quitem_qtyord * quitem_qty_invuomratio) *
+             (quitem_price / quitem_price_invuomratio),2) AS extprice,
+       quitem_custprice AS coitem_custprice,
+       CASE WHEN (quitem_custprice = 0.0) THEN 100.0
+            ELSE ((1.0 - (quitem_price / quitem_custprice)) * 100.0)
+       END AS discountfromcust,
+       quitem_unitcost AS coitem_unitcost,
+       ROUND((quitem_qtyord * quitem_qty_invuomratio) *
+             ((quitem_price / quitem_price_invuomratio) - quitem_unitcost),2) AS margin,
+       CASE WHEN (quitem_price = 0.0) THEN 100.0
+            ELSE ((quitem_price - quitem_unitcost) / quitem_price)
+       END AS marginpercent,
+       CASE WHEN (quitem_custpn != '') THEN quitem_custpn
+            ELSE item_number
+       END AS item_number_cust,
+       (quitem_qtyord / quitem_qty_invuomratio * item_prodweight) AS prodweight,
+       (quitem_qtyord / quitem_qty_invuomratio * item_packweight) AS packweight,
+       itemsite_qtyonhand,
+       'qty' AS coitem_qtyord_xtnumericrole,
+       'qty' AS qtyshipped_xtnumericrole,
+       'qty' AS balance_xtnumericrole,
+       'qty' AS qtyatshipping_xtnumericrole,
+       'qty' AS prodweight_xtnumericrole,
+       'qty' AS packweight_xtnumericrole,
+       'qty' AS itemsite_qtyonhand_xtnumericrole,
+       'salesprice' AS coitem_price_xtnumericrole,
+       'cost' AS coitem_unitcost_xtnumericrole,
+       'curr' AS margin_xtnumericrole,
+       'percent' AS marginpercent_xtnumericrole,
+       'curr' AS extprice_xtnumericrole
+  FROM item, uom AS quom, uom AS puom,
+       quitem LEFT OUTER JOIN (itemsite JOIN whsinfo ON (itemsite_warehous_id=warehous_id)) ON (quitem_itemsite_id=itemsite_id)
+ WHERE ( (quitem_item_id=item_id)
+   AND   (quitem_qty_uom_id=quom.uom_id)
+   AND   (quitem_price_uom_id=puom.uom_id)
+   AND   (quitem_quhead_id=<? value("quhead_id") ?>) )
+ORDER BY quitem_linenumber;
index 4492fac..e89fbc3 100644 (file)
@@ -1,13 +1,25 @@
 -- Group: quotes
 -- Name: detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT quhead.*, firstline(quhead_ordercomments) AS notes, quhead_id AS id,
-  CASE WHEN quhead_status = 'O' THEN <? value("open") ?>
-       WHEN quhead_status = 'C' THEN <? value("converted") ?>
-  ELSE <? value("undefined") ?> END AS quhead_status_qtdisplayrole,
+       calcQuoteAmt(quhead_id) AS ordertotal,
+       'extprice' AS ordertotal_xtnumericrole,
+       <? foreach("char_id_text_list") ?>
+         charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>,
+       <? endforeach ?>
+       <? foreach("char_id_list_list") ?>
+         charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>,
+       <? endforeach ?>
+       <? foreach("char_id_date_list") ?>
+         charass_alias<? literal("char_id_date_list") ?>.charass_value::date AS char<? literal("char_id_date_list") ?>,
+       <? endforeach ?>
+       CASE WHEN quhead_status = 'O' THEN <? value("open") ?>
+            WHEN quhead_status = 'C' THEN <? value("converted") ?>
+            ELSE <? value("undefined") ?>
+       END AS quhead_status_qtdisplayrole,
 <? if exists("customersOnly") ?>
        cust_id, cust_number, cust_name,
 <? endif ?>
@@ -22,6 +34,30 @@ FROM quhead
   LEFT OUTER 
 <? endif ?>
   JOIN custinfo ON (quhead_cust_id=cust_id)
+<? foreach("char_id_text_list") ?>
+  LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?> 
+             ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='QU') 
+            AND  (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=quhead_id)
+            AND  (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))
+  LEFT OUTER JOIN char char_alias<? literal("char_id_text_list") ?> 
+             ON (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=char_alias<? literal("char_id_text_list") ?>.char_id)
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+  LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?> 
+             ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='QU') 
+            AND  (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=quhead_id)
+            AND  (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))
+  LEFT OUTER JOIN char char_alias<? literal("char_id_list_list") ?> 
+             ON (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=char_alias<? literal("char_id_list_list") ?>.char_id)
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+  LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?> 
+             ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='QU') 
+            AND  (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=quhead_id)
+            AND  (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))
+  LEFT OUTER JOIN char char_alias<? literal("char_id_date_list") ?> 
+             ON (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=char_alias<? literal("char_id_date_list") ?>.char_id)
+<? endforeach ?>
 WHERE (checkQuoteSitePrivs(quhead_id, <? value("warehous_id") ?>))
 <? if exists("owner_username") ?> 
   AND (quhead_owner_username=<? value("owner_username") ?>) 
@@ -60,6 +96,7 @@ WHERE (checkQuoteSitePrivs(quhead_id, <? value("warehous_id") ?>))
 <? if exists("id") ?>
   AND  (quhead_id = <? value("id") ?>)
 <? endif ?>
+<? literal("charClause") ?>
 <? if exists("orderByCust") ?>
 ORDER BY cust_number, quhead_number;
 <? else ?>
index f97eeed..6d26113 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: receipt
 -- Name: detail
 -- Notes: used by enterPoReceipt
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 <? if exists("pohead_id") ?>
index b77ce17..f1e78d3 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: receipt
 -- Name: receiveAll
 -- Notes: used by enterPoReceipt, returnAuthorization, shipOrder
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 <? if exists ("shiphead_id") ?>
index 5ff78cc..23c2653 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: receivings
 -- Name: detail
 -- Notes: used by dspPoItemReceivingsByDate, dspPoItemReceivingsByItem, dspPoItemReceivingsByVendor
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT recv_id, 1 AS altid, recv_order_number AS ponumber,
index e916d9d..7d0b90a 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: reorderExceptionsByPlannerCode
 -- Name: detail
 -- Notes: used by dspReorderExceptionsByPlannerCode
---        Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 --        See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT itemsite_id, itemtype, warehous_code, item_number,
index 72231e4..e8b1e93 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: reports
 -- Name:  detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 <? if exists('byPackage') ?>
index 2d9a533..178cff0 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: reservations
 -- Name: detail
 -- Notes: used by dspReservations
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT source_id, order_number, scheddate,
@@ -32,11 +32,13 @@ UNION
 SELECT coitem_scheddate AS sortkey, 1 AS level, coitem_id AS source_id,
       (formatLocationName(itemloc_location_id) || ' ' || formatLotSerialNumber(itemloc_ls_id)) AS order_number,
        NULL AS totalqty, NULL AS relievedqty,
-       (itemlocrsrv_qty * coitem_qty_invuomratio) AS reservedqty,
+       (reserve_qty * coitem_qty_invuomratio) AS reservedqty,
        NULL AS balanceqty, NULL AS scheddate
-FROM itemlocrsrv, itemloc, coitem, itemsite
-WHERE ( (itemloc_id=itemlocrsrv_itemloc_id)
-  AND (coitem_id=itemlocrsrv_source_id)
+FROM reserve, itemloc, coitem, itemsite
+WHERE ( (itemloc_id=reserve_supply_id)
+  AND (reserve_supply_type='I')
+  AND (coitem_id=reserve_demand_id)
+  AND (reserve_demand_type='SO')
   AND (itemsite_id=coitem_itemsite_id)
   AND (itemsite_warehous_id=<? value("warehous_id") ?>)
   AND (itemsite_item_id=<? value("item_id") ?>) )
index b1535c2..7a61660 100644 (file)
@@ -2,7 +2,7 @@
 -- Name: detail
 -- Notes:
 -- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT DISTINCT rahead_id, rahead_number, rahead_billtoname,
index 9f0a270..a5ccea5 100644 (file)
@@ -1,19 +1,21 @@
 -- Group: runningAvailability
 -- Name: detail
 -- Notes: used by dspRunningAvailability, itemAvailabilityWorkbench
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT orderid, altorderid, ordertype, ordernumber, sequence, item_number,
-       duedate, qtyordered,  qtyreceived, balance,
+       duedate, amount, qtyordered,  qtyreceived, balance,
        balance AS runningavail,
 <? if exists("isReport") ?>
        CASE WHEN duedate = startOfTime() THEN ''
             ELSE formatDate(duedate) END AS f_duedate,
+       formatMoney(amount) AS f_amount,
        formatQty(qtyordered) AS f_qtyordered,
        formatQty(qtyreceived) AS f_qtyreceived,
        formatQty(balance) AS f_balance,
 <? endif ?>
+       notes,
        1 AS runningavail_xtrunningrole,
        <? value("qoh") ?> AS runningavail_xtrunninginit,
        CASE WHEN late THEN 'error' END AS duedate_qtforegroundrole,
@@ -22,6 +24,7 @@ SELECT orderid, altorderid, ordertype, ordernumber, sequence, item_number,
                  ordertype ~ <? value("plannedWo") ?> OR
                  ordertype ~ <? value("plannedTo") ?> THEN
           'emphasis' END AS qtforegroundrole,
+      'currency' AS amount_xtnumericrole,
       'qty' AS qtyordered_xtnumericrole,
       'qty' AS qtyreceived_xtnumericrole,
       'qty' AS balance_xtnumericrole
@@ -33,9 +36,11 @@ SELECT -1 AS orderid, -1 AS altorderid, 'QOH' AS ordertype,
        '' AS item_number,
        startOfTime() AS duedate,
        FALSE AS late,
+       0 AS amount,
        0 AS qtyordered,
        0 AS qtyreceived,
-       <? value("qoh") ?> AS balance
+       <? value("qoh") ?> AS balance,
+       '' AS notes
 UNION
 <? endif ?>
 <? if exists("MultiWhs") ?>
@@ -45,9 +50,11 @@ SELECT tohead_id AS orderid, toitem_id AS altorderid, 'T/O' AS ordertype,
        tohead_srcname || '/' || tohead_destname AS item_number,
        toitem_duedate AS duedate,
        (toitem_duedate < CURRENT_DATE) AS late,
+       (toitem_stdcost * toitem_qty_ordered) AS amount,
        toitem_qty_ordered AS qtyordered,
        toitem_qty_received AS qtyreceived,
-       noNeg(toitem_qty_ordered - toitem_qty_received) AS balance
+       noNeg(toitem_qty_ordered - toitem_qty_received) AS balance,
+       tohead_ordercomments AS notes
 FROM tohead, toitem
 WHERE ((toitem_tohead_id=tohead_id)
   AND  (toitem_status NOT IN ('C', 'X'))
@@ -62,9 +69,11 @@ SELECT tohead_id AS orderid, toitem_id AS altorderid, 'T/O' AS ordertype,
        tohead_srcname || '/' || tohead_destname AS item_number,
        toitem_duedate AS duedate,
        (toitem_duedate < CURRENT_DATE) AS late,
+       (toitem_stdcost * toitem_qty_ordered) AS amount,
        toitem_qty_ordered AS qtyordered,
        toitem_qty_received AS qtyreceived,
-       -1 * noNeg(toitem_qty_ordered - toitem_qty_shipped - qtyAtShipping('TO', toitem_id)) AS balance
+       -1 * noNeg(toitem_qty_ordered - toitem_qty_shipped - qtyAtShipping('TO', toitem_id)) AS balance,
+       tohead_ordercomments AS notes
        -- TODO: old code had ^^^^ for formatted balance and vvvv used to calc running avail! which is right?
        -- -1 * noNeg(toitem_qty_ordered - toitem_qty_received) AS balance
 FROM tohead, toitem
@@ -83,9 +92,11 @@ SELECT wo_id AS orderid, -1 AS altorderid,
        item_number,
        wo_duedate AS duedate,
        (wo_duedate < CURRENT_DATE) AS late,
+       (itemCost(wo_itemsite_id) * wo_qtyord) AS amount,
        wo_qtyord AS qtyordered,
        wo_qtyrcv AS qtyreceived,
-       noNeg(wo_qtyord - wo_qtyrcv) AS balance
+       noNeg(wo_qtyord - wo_qtyrcv) AS balance,
+       wo_prodnotes AS notes
 FROM wo, itemsite, item
 WHERE ((wo_status<>'C')
   AND  (wo_itemsite_id=itemsite_id)
@@ -104,9 +115,11 @@ SELECT wo_id AS orderid, -1 AS altorderid,
        item_number,
        wo_duedate AS duedate,
        (wo_duedate < CURRENT_DATE) AS late,
+       (womatl_cost * womatl_qtyreq) AS amount,
        womatl_qtyreq AS qtyordered,
        COALESCE(SUM(abs(invhist_invqty)),0) AS qtyreceived,
-       noNeg(womatl_qtyreq - COALESCE(SUM(abs(invhist_invqty)),0)) AS balance
+       noNeg(womatl_qtyreq - COALESCE(SUM(abs(invhist_invqty)),0)) AS balance,
+       wo_prodnotes AS notes
 FROM womatl
   JOIN wo ON (wo_id=womatl_wo_id)
   JOIN itemsite ON (womatl_itemsite_id=itemsite_id)
@@ -118,7 +131,7 @@ WHERE ((wo_status<>'C')
   AND  (itemsite_warehous_id=<? value("warehous_id") ?>)
   AND  (itemsite_item_id=<? value("item_id") ?>)
   AND  (item_type = 'T'))
-GROUP BY wo_id, wo_duedate, item_number, womatl_qtyreq
+GROUP BY wo_id, wo_duedate, item_number, womatl_qtyreq, womatl_cost, wo_prodnotes
 
 <? if exists("Manufacturing") ?>
 UNION
@@ -129,9 +142,11 @@ SELECT wo_id AS orderid, -1 AS altorderid,
        item_number,
        wo_duedate AS duedate,
        (wo_duedate < CURRENT_DATE) AS late,
+       (itemCost(wo_itemsite_id) * wo_qtyord * brddist_stdqtyper) AS amount,
        (wo_qtyord * brddist_stdqtyper) AS qtyordered,
        (wo_qtyrcv * brddist_stdqtyper) AS qtyreceived,
-       noNeg((wo_qtyord - wo_qtyrcv) * brddist_stdqtyper) AS balance
+       noNeg((wo_qtyord - wo_qtyrcv) * brddist_stdqtyper) AS balance,
+       wo_prodnotes AS notes
 FROM xtmfg.brddist, wo, itemsite, item
 WHERE ((wo_status<>'C')
   AND  (brddist_wo_id=wo_id)
@@ -151,9 +166,11 @@ SELECT wo_id AS orderid, womatl_id AS altorderid,
       woi.item_number,
       womatl_duedate AS duedate,
       FALSE AS late,
+      (itemCost(womatl_itemsite_id) * itemuomtouom(womatlis.itemsite_item_id, womatl_uom_id, NULL, womatl_qtyreq)) AS amount,
       itemuomtouom(womatlis.itemsite_item_id, womatl_uom_id, NULL, womatl_qtyreq) AS qtyordered,
       itemuomtouom(womatlis.itemsite_item_id, womatl_uom_id, NULL, womatl_qtyiss) AS qtyreceived,
-      itemuomtouom(womatlis.itemsite_item_id, womatl_uom_id, NULL, (noNeg(womatl_qtyreq - womatl_qtyiss) * -1)) AS balance
+      itemuomtouom(womatlis.itemsite_item_id, womatl_uom_id, NULL, (noNeg(womatl_qtyreq - womatl_qtyiss) * -1)) AS balance,
+      wo_prodnotes AS notes
 FROM womatl, wo, itemsite AS wois, item AS woi, itemsite AS womatlis, item AS womatli
 WHERE ((wo_status<>'C')
   AND  (wo_itemsite_id=wois.itemsite_id)
@@ -174,9 +191,11 @@ SELECT wo_id AS orderid, womatl_id AS altorderid,
       woi.item_number,
       womatl_duedate AS duedate,
       FALSE AS late,
+      (womatl_cost * itemuomtouom(womatlis.itemsite_item_id, womatl_uom_id, NULL, womatl_qtyreq)) AS amount,
       itemuomtouom(womatlis.itemsite_item_id, womatl_uom_id, NULL, womatl_qtyreq) AS qtyordered,
       COALESCE(SUM(invhist_invqty),0) AS qtyreceived,
-      (itemuomtouom(womatlis.itemsite_item_id, womatl_uom_id, NULL, (noNeg(womatl_qtyreq))) - COALESCE(SUM(invhist_invqty),0)) * -1 AS balance
+      (itemuomtouom(womatlis.itemsite_item_id, womatl_uom_id, NULL, (noNeg(womatl_qtyreq))) - COALESCE(SUM(invhist_invqty),0)) * -1 AS balance,
+      wo_prodnotes AS notes
 FROM itemsite AS wois, item AS woi, itemsite AS womatlis, item AS womatli, wo, womatl
   LEFT OUTER JOIN womatlpost ON (womatl_id=womatlpost_womatl_id)
   LEFT OUTER JOIN invhist ON ((womatlpost_invhist_id=invhist_id)
@@ -190,21 +209,24 @@ WHERE ((wo_status<>'C')
   AND  (womatlis.itemsite_item_id=<? value("item_id") ?>)
   AND  (womatlis.itemsite_warehous_id=<? value("warehous_id") ?>)
   AND  (womatl_itemsite_id=womatlis.itemsite_id) )
-GROUP BY wo_id, woi.item_number, womatl_id, womatl_duedate, womatlis.itemsite_item_id, womatl_uom_id, womatl_qtyreq
+GROUP BY wo_id, woi.item_number, womatl_id, womatl_duedate, womatlis.itemsite_item_id, womatl_uom_id, womatl_qtyreq, womatl_cost, wo_prodnotes
 
 UNION
 SELECT pohead_id AS orderid, poitem_id AS altorderid,
       'P/O' AS ordertype,
       TEXT(pohead_number) AS ordernumber,
       1 AS sequence,
-      '' AS item_number,
+      vend_name AS item_number,
       poitem_duedate AS duedate,
       (poitem_duedate < CURRENT_DATE) AS late,
+      (poitem_unitprice * poitem_qty_ordered) AS amount,
       (poitem_qty_ordered * poitem_invvenduomratio) AS qtyordered,
       (NoNeg(poitem_qty_received - poitem_qty_returned) * poitem_invvenduomratio) AS qtyreceived,
-      (noNeg(poitem_qty_ordered - poitem_qty_received) * poitem_invvenduomratio) AS balance
-FROM pohead, poitem, itemsite, item
-WHERE ((poitem_pohead_id=pohead_id)
+      (noNeg(poitem_qty_ordered - poitem_qty_received) * poitem_invvenduomratio) AS balance,
+       pohead_comments AS notes
+FROM pohead, vendinfo, poitem, itemsite, item
+WHERE ((vend_id=pohead_vend_id)
+  AND  (poitem_pohead_id=pohead_id)
   AND  (poitem_status <> 'C')
   AND  (poitem_itemsite_id=itemsite_id)
   AND  (itemsite_warehous_id=<? value("warehous_id") ?>)
@@ -219,9 +241,11 @@ SELECT cohead_id AS orderid, coitem_id AS altorderid,
        cust_name AS item_number,
        coitem_scheddate AS duedate,
        (coitem_scheddate < CURRENT_DATE) AS late,
+       (coitem_price * coitem_qtyord) AS amount,
        (coitem_qtyord * coitem_qty_invuomratio) AS qtyordered,
        (coitem_qty_invuomratio * (coitem_qtyshipped - coitem_qtyreturned + qtyAtShipping(coitem_id))) AS qtyreceived,
-       (coitem_qty_invuomratio * noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned - qtyAtShipping(coitem_id)) * -1) AS balance
+       (coitem_qty_invuomratio * noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned - qtyAtShipping(coitem_id)) * -1) AS balance,
+       cohead_ordercomments AS notes
 FROM coitem, cohead, custinfo, itemsite, item
 WHERE ((coitem_status='O')
   AND  (cohead_cust_id=cust_id)
@@ -243,9 +267,11 @@ SELECT planord_id AS orderid, -1 AS altorderid,
        '' AS item_number,
        planord_duedate AS duedate,
        FALSE AS late,
+       (itemCost(planord_itemsite_id) * planord_qty) AS amount,
        planord_qty AS qtyordered,
        NULL AS qtyreceived,
-       planord_qty AS balance
+       planord_qty AS balance,
+       planord_comments AS notes
 FROM planord, itemsite
 WHERE ((planord_type='P')
   AND  (planord_itemsite_id=itemsite_id)
@@ -262,9 +288,11 @@ SELECT planord_id AS orderid, -1 AS altorderid,
        '' AS item_number,
        planord_duedate AS duedate,
        FALSE AS late,
+       (itemCost(planord_itemsite_id) * planord_qty) AS amount,
        planord_qty AS qtyordered,
        NULL AS qtyreceived,
-       planord_qty AS balance
+       planord_qty AS balance,
+       planord_comments AS notes
 FROM planord, itemsite
 WHERE ((planord_type='W')
   AND  (planord_itemsite_id=itemsite_id)
@@ -282,9 +310,11 @@ SELECT planord_id AS orderid, -1 AS altorderid,
        item_number,
        planord_duedate AS duedate,
        FALSE AS late,
+       (itemCost(planreq_itemsite_id) * planreq_qty) AS amount,
        planreq_qty AS qtyordered,
        NULL AS qtyreceived,
-       planreq_qty AS balance
+       planreq_qty AS balance,
+       planord_comments AS notes
 FROM planreq
   JOIN itemsite ON (itemsite_id=planreq_itemsite_id)
   JOIN item ON (item_id=itemsite_item_id)
@@ -304,9 +334,11 @@ SELECT planord_id AS orderid, -1 AS altorderid,
        srcwhsinfo.warehous_code || '/' || whsinfo.warehous_code AS item_number,
        planord_duedate AS duedate,
        FALSE AS late,
+       (itemCost(planord_itemsite_id) * planord_qty) AS amount,
        planord_qty AS qtyordered,
        NULL AS qtyreceived,
-       planord_qty AS balance
+       planord_qty AS balance,
+       planord_comments AS notes
 FROM planord JOIN itemsite ON (itemsite.itemsite_id=planord_itemsite_id)
              JOIN whsinfo ON (whsinfo.warehous_id=itemsite.itemsite_warehous_id)
              JOIN itemsite srcitemsite ON (srcitemsite.itemsite_id=planord_supply_itemsite_id)
@@ -325,9 +357,11 @@ SELECT planord_id AS orderid, -1 AS altorderid,
        srcwhsinfo.warehous_code || '/' || whsinfo.warehous_code AS item_number,
        planord_duedate AS duedate,
        FALSE AS late,
+       (itemCost(planord_itemsite_id) * planord_qty) AS amount,
        planord_qty AS qtyordered,
        NULL AS qtyreceived,
-       (planord_qty * -1) AS balance
+       (planord_qty * -1) AS balance,
+       planord_comments AS notes
 FROM planord JOIN itemsite ON (itemsite.itemsite_id=planord_itemsite_id)
              JOIN whsinfo ON (whsinfo.warehous_id=itemsite.itemsite_warehous_id)
              JOIN itemsite srcitemsite ON (srcitemsite.itemsite_id=planord_supply_itemsite_id)
@@ -351,9 +385,11 @@ SELECT planreq_id AS orderid, -1 AS altorderid,
              ) AS item_number,
        planord_startdate AS duedate,
        FALSE AS late,
+       (itemCost(planreq_itemsite_id) * planreq_qty) AS amount,
        planreq_qty AS f_qtyordered,
        NULL AS qtyreceived,
-       (planreq_qty * -1) AS balance
+       (planreq_qty * -1) AS balance,
+       planreq_notes AS notes
 FROM planreq, planord, itemsite, item
 WHERE ((planreq_source='P')
   AND  (planreq_source_id=planord_id)
@@ -371,9 +407,11 @@ SELECT pr_id AS orderid, -1 AS altorderid,
        '' AS item_number,
        pr_duedate AS duedate,
        FALSE AS late,
+       (itemCost(pr_itemsite_id) * pr_qtyreq) AS amount,
        pr_qtyreq AS qtyordered,
        NULL AS qtyreceived,
-       pr_qtyreq AS balance
+       pr_qtyreq AS balance,
+       pr_releasenote AS notes
 FROM pr, itemsite, item
 WHERE ((pr_itemsite_id=itemsite_id)
   AND  (itemsite_item_id=item_id)
index 0ad17b9..f6815b5 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: salesAccounts
 -- Name: detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT salesaccnt_id,
index 26321ee..50da06f 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: salesHistory
 -- Name: detail
 -- Notes: 
---        Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 --        See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT cohist.*,
index b65ae27..d21d279 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: salesOrderItems
 -- Name: detail
 -- Notes: used by dspBacklogByCustomer, dspBacklogByItem, dspBacklogByParameterList, dspBacklogBySalesOrder, dspBookingsByCustomer, dspBookingsByCustomerGroup, dspBookingsByItem, dspBookingsByProductCategory, dspBookingsBySalesRep, dspBookingsByShipTo, dspSalesOrdersByItem
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT
index 5a222a4..ba274e2 100644 (file)
@@ -1,13 +1,14 @@
 -- Group: salesOrderItems
 -- Name: list
 -- Notes: used by salesOrder
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
--- See www.xtuple.com/CPAL for the full text of the software license.
+--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+--        See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT coitem_id, coitem_altid, groupby,
        coitem_linenumber, coitem_subnumber, f_linenumber,
        warehous_code, item_number, item_type, description,
        item_number_cust, item_descrip1_cust, item_descrip2_cust, item_barcode,
+       prodweight, packweight,
        enhanced_status, coitem_firm,
        qty_uom, price_uom, ship_uom,
        coitem_memo,
@@ -24,6 +25,7 @@ SELECT coitem_id, coitem_altid, groupby,
        CASE WHEN (extprice_shipped > 0.0) THEN formatMoney(extprice_shipped) ELSE NULL END AS f_extprice_shipped,
 -- end formatted columns
        coitem_scheddate, coitem_price, coitem_custprice, discountfromcust,
+       coitem_unitcost, margin, marginpercent,
        coitem_qtyord, qtyshipped, balance, qtyatshipping,
        extprice, extprice_shipped,
        CASE WHEN (discountfromcust=100.0) THEN 'N/A' END AS discountfromcust_qtdisplayrole,
@@ -31,10 +33,15 @@ SELECT coitem_id, coitem_altid, groupby,
        'qty' AS qtyshipped_xtnumericrole,
        'qty' AS balance_xtnumericrole,
        'qty' AS qtyatshipping_xtnumericrole,
+       'qty' AS prodweight_xtnumericrole,
+       'qty' AS packweight_xtnumericrole,
        'salesprice' AS coitem_price_xtnumericrole,
        'salesprice' AS coitem_custprice_xtnumericrole,
+       'cost' AS coitem_unitcost_xtnumericrole,
        'curr' AS extprice_xtnumericrole,
        'curr' AS extprice_shipped_xtnumericrole,
+       'curr' AS margin_xtnumericrole,
+       'percent' AS marginpercent_xtnumericrole,
        CASE WHEN fetchMetricBool('EnableSOShipping') AND
                  coitem_scheddate > CURRENT_DATE AND
                  (noNeg(coitem_qtyord) <> qtyAtShipping('SO', coitem_id)) THEN 'future'
@@ -49,7 +56,16 @@ SELECT coitem_id, coitem_altid, groupby,
        CASE WHEN coitem_subnumber = 0 THEN 0
             ELSE 1
        END AS xtindentrole,
-       spplytype, ordrnumbr
+       spplytype, ordrnumbr,
+       itemsite_qtyonhand,
+       'qty' AS itemsite_qtyonhand_xtnumericrole
+<? if exists("includeReservations") ?>
+       ,
+       reserved,
+       reservable,
+       'qty' AS reserved_xtnumericrole,
+       'qty' AS reservable_xtnumericrole
+<? endif?>
 FROM (
 SELECT coitem_id,
        CASE WHEN (coitem_status='C') THEN 1
@@ -70,30 +86,10 @@ SELECT coitem_id,
             ELSE item_descrip2
        END AS item_descrip2_cust,
        formatitemsitebarcode(itemsite_id) AS item_barcode,
+       (coitem_qtyord / coitem_qty_invuomratio * item_prodweight) AS prodweight,
+       (coitem_qtyord / coitem_qty_invuomratio * item_packweight) AS packweight,
        coitem_status, coitem_firm,
-      (CASE WHEN (coitem_status='O' AND (SELECT cust_creditstatus FROM custinfo WHERE cust_id=cohead_cust_id)='H') THEN 'H'
-            WHEN (coitem_status='O' AND ((SELECT SUM(invcitem_billed)
-                                            FROM cohead, invchead, invcitem
-                                           WHERE ((CAST(invchead_ordernumber AS text)=cohead_number)
-                                             AND  (invcitem_invchead_id=invchead_id)
-                                             AND  (invcitem_item_id=item_id)
-                                             AND  (invcitem_warehous_id=warehous_id)
-                                             AND  (invcitem_linenumber=coitem_linenumber)
-                                             AND  (cohead_id=coitem_cohead_id))) >= coitem_qtyord)) THEN 'I'
-            WHEN (coitem_status='O' AND ((SELECT SUM(invcitem_billed)
-                                            FROM cohead, invchead, invcitem
-                                           WHERE ((CAST(invchead_ordernumber AS text)=cohead_number)
-                                             AND  (invcitem_invchead_id=invchead_id)
-                                             AND  (invcitem_item_id=item_id)
-                                             AND  (invcitem_warehous_id=warehous_id)
-                                             AND  (invcitem_linenumber=coitem_linenumber)
-                                             AND  (cohead_id=coitem_cohead_id))) > 0)) THEN 'P'
-            WHEN (coitem_status='O' AND (itemsite_qtyonhand - qtyAllocated(itemsite_id, CURRENT_DATE)
-                                         + qtyOrdered(itemsite_id, CURRENT_DATE))
-                                          >= ((coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned) * coitem_qty_invuomratio)) THEN 'R'
-            ELSE coitem_status END
-       || CASE WHEN (coitem_firm) THEN 'F' ELSE '' END
-       ) AS enhanced_status,
+       getSoitemStatus(coitem_id) AS enhanced_status,
        quom.uom_name AS qty_uom, puom.uom_name AS price_uom,
        itemSellingUOM(item_id) AS ship_uom,
        coitem_memo,
@@ -101,6 +97,12 @@ SELECT coitem_id,
        CASE WHEN (coitem_custprice = 0.0) THEN 100.0
             ELSE ((1.0 - (coitem_price / coitem_custprice)) * 100.0)
        END AS discountfromcust,
+       coitem_unitcost,
+       ROUND((coitem_qtyord * coitem_qty_invuomratio) *
+             ((coitem_price / coitem_price_invuomratio) - coitem_unitcost),2) AS margin,
+       CASE WHEN (coitem_price = 0.0) THEN 100.0
+            ELSE ((coitem_price - coitem_unitcost) / coitem_price)
+       END AS marginpercent,
        noNeg(coitem_qtyshipped - coitem_qtyreturned) AS qtyshipped,
        noNeg(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned) AS balance,
        qtyAtShipping('SO', coitem_id) AS qtyatshipping,
@@ -117,7 +119,13 @@ SELECT coitem_id,
             WHEN coitem_order_type='P' THEN (pohead_number || '-' || poitem_linenumber)
             WHEN coitem_order_type='R' THEN (pr_number || '-' || pr_subnumber)
             ELSE TEXT (' ')
-       END AS ordrnumbr
+       END AS ordrnumbr,
+       itemsite_qtyonhand
+<? if exists("includeReservations") ?>
+       ,
+       coitem_qtyreserved AS reserved,
+       itemsite_qtyonhand - qtyreserved(itemsite_id) AS reservable
+<? endif?>
   FROM cohead
        JOIN coitem ON (coitem_cohead_id=cohead_id)
        JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
index efbec29..e079f37 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: salesOrderStatus
 -- Name: detail
 -- Notes: used by dspSalesOrderStatus
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT coitem_id, coitem_linenumber, item_number,
index 9e98bb0..217186b 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: salesOrders
 -- Name: detail
 -- Notes: used by dspSalesOrdersByCustomer, dspSalesOrdersByCustomerPO, dspSalesOrdersByParameterList
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT cohead_id, cust_id,
index 9b971f8..83f90c7 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: saletype
 -- Name: table
 -- Notes: maintain saletype table
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 <? if exists("ViewMode") ?>
index e911e8d..8baf0f7 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: schedule
 -- Name:  plannedorders
 -- Notes: used by dpsPlannedOrdersByItem, dspPlannedOrdersByPlannerCode, dspPlannedRevenueExpensesByPlannerCode
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
  SELECT *,
         plorevenue - plocost AS profit,
index b8d2180..5769e0a 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: scripts
 -- Name:  detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 <? if exists('byPackage') ?>
index 142449e..a0373ba 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: selectPayments
 -- Name: applyallcredits
 -- Notes: used by selectPayments
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 
index 267bbf4..fda70ae 100644 (file)
@@ -1,8 +1,8 @@
 -- Group: shipments
 -- Name: detail
 -- Notes: used by dspShipmentsByDate, dspShipmentsBySalesOrder, dspShipmentsByShipment
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
--- See www.xtuple.com/CPAL for the full text of the software license.
+--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+--        See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT shiphead_id, lineitem_id,
        CASE WHEN (level=0) THEN order_number
@@ -28,6 +28,7 @@ SELECT shiphead_id, lineitem_id,
        formatQty(qtyord) AS f_qtyord,
        qtyshipped,
        formatQty(qtyshipped) AS f_qtyshipped,
+       notes,
        'qty' AS qtyord_xtnumericrole,
        'qty' AS qtyshipped_xtnumericrole,
        'curr' AS shiphead_freight_xtnumericrole,
@@ -37,7 +38,8 @@ SELECT shiphead_id, lineitem_id,
        CASE WHEN (COALESCE(shiphead_freight, 0) = 0) THEN '' END AS shiphead_freight_qtdisplayrole,
        level AS xtindentrole
 FROM (
-SELECT shiphead_id, -1 AS lineitem_id, cohead_number AS sortkey1, shiphead_number AS sortkey2, 0 AS level,
+SELECT DISTINCT
+       shiphead_id, -1 AS lineitem_id, cohead_number AS sortkey1, shiphead_number AS sortkey2, 0 AS level,
        shiphead_order_type,
        shiphead_number,
        cohead_number AS order_number, 
@@ -50,8 +52,15 @@ SELECT shiphead_id, -1 AS lineitem_id, cohead_number AS sortkey1, shiphead_numbe
        '' AS itemdescription,
        '' AS warehous_code,
        0 AS qtyord,
-       0 AS qtyshipped
-FROM shiphead, cohead, custinfo
+       0 AS qtyshipped,
+       firstline(shiphead_notes) AS notes
+FROM shiphead JOIN cohead ON (cohead_id=shiphead_order_id)
+              JOIN custinfo ON (cust_id=cohead_cust_id)
+<? if exists("warehous_id") ?>
+              JOIN shipitem ON (shipitem_shiphead_id=shiphead_id)
+              JOIN coitem ON (coitem_id=shipitem_orderitem_id)
+              JOIN itemsite ON (itemsite_id=coitem_itemsite_id)
+<? endif ?>
 WHERE ( (shiphead_order_id=cohead_id)
  AND (cohead_cust_id=cust_id)
  AND (shiphead_shipped)
@@ -59,6 +68,9 @@ WHERE ( (shiphead_order_id=cohead_id)
 <? if exists("startDate") ?>
  AND (shiphead_shipdate BETWEEN <? value("startDate") ?> and <? value("endDate") ?>)
 <? endif ?>
+<? if exists("warehous_id") ?>
+ AND (itemsite_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
 <? if exists("sohead_id") ?>
  AND (cohead_id = <? value("sohead_id") ?>)
 <? endif ?>
@@ -80,7 +92,8 @@ SELECT shiphead_id, coitem_id AS lineitem_id, cohead_number AS sortkey1, shiphea
        (item_descrip1 || ' ' || item_descrip2) AS itemdescription,
        warehous_code,
        coitem_qtyord AS qtyord,
-       SUM(shipitem_qty) AS qtyshipped
+       SUM(shipitem_qty) AS qtyshipped,
+       '' AS notes
 FROM shipitem, shiphead, coitem, cohead, custinfo, itemsite, item, whsinfo
 WHERE ( (shipitem_shiphead_id=shiphead_id)
  AND (shipitem_orderitem_id=coitem_id)
@@ -95,6 +108,9 @@ WHERE ( (shipitem_shiphead_id=shiphead_id)
 <? if exists("startDate") ?>
  AND (shiphead_shipdate BETWEEN <? value("startDate") ?> and <? value("endDate") ?>)
 <? endif ?>
+<? if exists("warehous_id") ?>
+ AND (itemsite_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
 <? if exists("sohead_id") ?>
  AND (cohead_id = <? value("sohead_id") ?>)
 <? endif ?>
@@ -122,7 +138,8 @@ SELECT shiphead_id, -1 AS lineitem_id, tohead_number AS sortkey1, shiphead_numbe
        '' AS itemdescription,
        '' AS warehous_code,
        0 AS qtyord,
-       0 AS qtyshipped
+       0 AS qtyshipped,
+       firstline(shiphead_notes) AS notes
 FROM shiphead, tohead 
 WHERE ( (shiphead_order_id=tohead_id)
  AND (shiphead_shipped)
@@ -130,6 +147,9 @@ WHERE ( (shiphead_order_id=tohead_id)
 <? if exists("startDate") ?>
  AND (shiphead_shipdate BETWEEN <? value("startDate") ?> and <? value("endDate") ?>)
 <? endif ?>
+<? if exists("warehous_id") ?>
+ AND (tohead_src_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
 <? if exists("tohead_id") ?>
  AND (tohead_id = <? value("tohead_id") ?>)
 <? endif ?>
@@ -151,7 +171,8 @@ SELECT shiphead_id, toitem_id AS lineitem_id, tohead_number AS sortkey1, shiphea
        (item_descrip1 || ' ' || item_descrip2) AS itemdescription,
        tohead_srcname AS warehous_code,
        toitem_qty_ordered AS qtyord,
-       SUM(shipitem_qty) AS qtyshipped
+       SUM(shipitem_qty) AS qtyshipped,
+       '' AS notes
 FROM shipitem, shiphead, toitem, tohead, item 
 WHERE ( (shipitem_shiphead_id=shiphead_id)
  AND (shipitem_orderitem_id=toitem_id)
@@ -163,6 +184,9 @@ WHERE ( (shipitem_shiphead_id=shiphead_id)
 <? if exists("startDate") ?>
  AND (shiphead_shipdate BETWEEN <? value("startDate") ?> and <? value("endDate") ?>)
 <? endif ?>
+<? if exists("warehous_id") ?>
+ AND (tohead_src_warehous_id = <? value("warehous_id") ?>)
+<? endif ?>
 <? if exists("tohead_id") ?>
  AND (tohead_id = <? value("tohead_id") ?>)
 <? endif ?>
@@ -174,7 +198,7 @@ GROUP BY shiphead_id, toitem_id, shiphead_order_type, shiphead_number,
          tohead_number, shiphead_shipdate,
          toitem_linenumber, item_number, item_descrip1, item_descrip2,
          tohead_srcname, shiphead_tracknum, toitem_qty_ordered, 
-         shiphead_freight, shiphead_freight_curr_id 
+         shiphead_freight, shiphead_freight_curr_id, notes
 <? endif ?>
    ) AS data
 ORDER BY sortkey1, sortkey2, level, linenumber DESC;
index ff0815e..3c48657 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: shippingForm
 -- Name: shipment
 -- Notes: used by printShippingForm
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT cohead_id AS order_id, cohead_shiptoname AS shipto, 
index 31be0b3..bdd9837 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: slowMovingInventoryByClassCode
 -- Name: detail
 -- Notes: used by dspSlowMovingInventoryByClassCode
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT itemsite_id, warehous_code, item_number,
index ae1dd27..5650b5c 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: standardJournalHistory
 -- Name: detail
 -- Notes: used by dspStandardJournalHistory
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT gltrans_sequence, gltrans_id,
index 50c2911..2096fa5 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: substituteAvailability
 -- Name: detail
 -- Notes: used by dspSubstituteAvailabilityByItem
---        Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+--        Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 --        See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT s_itemsite_id, warehous_code, item_number, itemdescrip,
index 5c76a26..2fa1ea0 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: summarizedBacklogByWarehouse
 -- Name: counts
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT COUNT(coitem.*) AS totalitems 
index 48a25e8..8b3d0ba 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: summarizedBacklogByWarehouse
 -- Name: detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT * FROM (
index 593aae9..e0ad31d 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: summarizedBacklogByWarehouse
 -- Name: qtys
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT formatQty(COALESCE(SUM(coitem_qtyord - coitem_qtyshipped + coitem_qtyreturned), 0)) AS f_totalqty 
index 50dc2f6..c6be609 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: summarizedBacklogByWarehouse
 -- Name: totals
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT COUNT(cohead_id) AS totalorders 
index ef57cf8..3492d58 100644 (file)
@@ -1,12 +1,10 @@
 -- Group: summarizedBankrecHistory
 -- Name: detail
 -- Notes: used by dspSummarizedBankrecHistory
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
-SELECT bankrec_posted, bankrec_postdate,
-       bankrec_username, bankrec_opendate,
-       bankrec_enddate, bankrec_openbal, bankrec_endbal,
+SELECT *,
        'curr' AS bankrec_openbal_xtnumericrole,
        'curr' AS bankrec_endbal_xtnumericrole
 FROM bankrec
index db01e09..fcbd7eb 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: summarizedGLTransactions
 -- Name: detail
 -- Notes: used by dspSummarizedGLTransactions
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT accnt_id, gltrans_id,
index f90b469..4cc1e3b 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: summarizedSalesHistory
 -- Name: detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT 1 AS dummy,
index caa1c76..e3393e2 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: taxAuthorities
 -- Name:  detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT 
index 2fcec04..f222ce0 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: taxBreakdown
 -- Name: detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 <? if exists("invchead_id") ?>
index 4eb1265..221fd42 100644 (file)
@@ -3,7 +3,7 @@
 -- Notes:
 -----------BEGIN SUMMARY----------
 -- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 <? if exists("summary") ?>
index cd2dcd7..b2cf065 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: timePhasedAvailability
 -- Name: detail
 -- Notes: used by dspTimePhasedAvailability
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT itemsite_id, itemtype,
index b38bc4e..32cd6d3 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: timePhasedBookings
 -- Name: detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT
index 5bf696e..3ac28d8 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: timePhasedSales
 -- Name: detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT
index 0459941..7290d5d 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: timePhasedUsageStatisticsByItem
 -- Name: detail
 -- Notes: used by dspTimePhasedUsageStatisticsByItem
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 
index 7b295d5..6ca7daf 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: todolist
 -- Name:  detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT * FROM (
index 99b62b8..cdb08dd 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: trialBalances
 -- Name: detail
 -- Notes: used by dspTrialBalances
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT accnt_id, period_id, accnt_descrip, trialbal_dirty,
index 3245bdb..68d84a8 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: uiforms
 -- Name:  detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 <? if exists('byPackage') ?>
index 69f183b..99f8b82 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: unbalancedQOHByClassCode
 -- Name: detail
 -- Notes: used by dspUnbalancedQOHByClassCode
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT itemsite_id, warehous_code, item_number,
index 3760bf6..a8ffcd8 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: undefinedManufacturedItems
 -- Name: detail
 -- Notes: used by dspUndefinedManufacturedItems
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT item_id, 2, item_number, (item_descrip1 || ' ' || item_descrip2) AS itemdescrip,
index 06142e3..df006fc 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: uninvoicedReceivings
 -- Name: detail
 -- Notes: used by dspUninvoicedReceivings
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT recv_id AS id,
index 7dffb1d..0cb0a33 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: uninvoicedShipments
 -- Name: detail
 -- Notes: used by uninvoicedShipments
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT cohead_id, shipitem_id, cohead_number, coitem_linenumber,
index 26b3927..51e032f 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: unpostedCashReceipts
 -- Name: detail
 -- Notes: Used by arWorkBench, cashReceiptsEditList
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT DISTINCT
index 755810e..567a467 100644 (file)
@@ -2,7 +2,7 @@
 -- Name: detail
 -- Notes: used by unpostedPoReceipts
 ---------PURCHASE ORDERS----------
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT recv_id, recv_orderitem_id, recv_order_number, recv_order_type,
index daac442..fefecdc 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: unusedPurchasedItems
 -- Name: detail
 -- Notes: used by dspUnusedPurchasedItems.cpp
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT DISTINCT item_id, item_number,
index 046406e..27f5a0d 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: uoms
 -- Name: item
 -- Notes: used by bomItem
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT uom_id, uom_name
index 56bb387..12ac21f 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: updateListPrices
 -- Name:  update
 -- Notes: Calculates and immediately updates list prices to the database
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 UPDATE item SET item_listprice=
index 657346f..9541d92 100644 (file)
@@ -2,7 +2,7 @@
 -- Name: add
 -- Notes:
 -- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
   INSERT INTO selsched
index ca05cf4..e14e280 100644 (file)
@@ -2,7 +2,7 @@
 -- Name: availsched
 -- Notes:
 -- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT ipshead_id, ipshead_name, ipshead_descrip,
index 565c102..2185b07 100644 (file)
@@ -2,7 +2,7 @@
 -- Name: createselsched
 -- Notes:
 -- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 CREATE TEMPORARY TABLE selsched (
index a74422e..4781fee 100644 (file)
@@ -2,7 +2,7 @@
 -- Name: dropselsched
 -- Notes:
 -- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 DROP TABLE selsched;
index 990ad6a..9925fbb 100644 (file)
@@ -2,7 +2,7 @@
 -- Name: remove
 -- Notes:
 -- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 DELETE FROM selsched
index 966e8bd..fe7fc39 100644 (file)
@@ -2,7 +2,7 @@
 -- Name: selsched
 -- Notes:
 -- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT selsched_ipshead_id, ipshead_name, ipshead_descrip
index cd080cb..27e5f04 100644 (file)
@@ -2,7 +2,7 @@
 -- Name: update
 -- Notes:
 -- Notes:
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 UPDATE ipsiteminfo SET
index 9565e25..fbfab5d 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: updateprices
 -- Name: updatechar
 -- Notes: used by updatePrices
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 UPDATE ipsitemchar SET
index d7ed14d..39cd9bb 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: updateReorderLevels
 -- Name:  post
 -- Notes: itemsite with new reorder level
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 UPDATE itemsite SET
index cba98fc..729fe2e 100644 (file)
@@ -1,12 +1,11 @@
 -- Group: updateReorderLevels
 -- Name:  query
 -- Notes: Calculates reorder point levels and returns a proposed result set
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT *,
   'qty' AS reordlvl_curr_level_xtnumericrole,
-  'qty' AS reordlvl_calc_level_xtnumericrole,
   'qty' AS reordlvl_total_usage_xtnumericrole
 FROM updateReorderLevel((
   SELECT array(
index cbe4db1..e8b4cab 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: updateReorderLevels
 -- Name:  update
 -- Notes: Calculates and immediatly updates reorder point levels to the database
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT updateReorderLevel(itemsite_id,<? value("daysOfStock") ?>, 
index 67838f3..8fa9adb 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: usageStatistics
 -- Name: detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT *,
index 499bd2a..5931019 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: validLocationsByItem
 -- Name: detail
 -- Notes: used by dspValidLocationsByItem.cpp
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT location_id, warehous_code,
index c404b25..9cc1d99 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: vendorAPHistory
 -- Name: detail
 -- Notes: used by dspVendorAPHistory
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT apopen_id, -1 AS applyid, 0 AS type,
index 99c6ecc..9049f1a 100644 (file)
@@ -1,18 +1,51 @@
 -- Group: vendors
 -- Name:  detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT 
   vend_id, vend_vendtype_id, 
   vend_active, vend_number, vend_name,
   vendtype_code,
+<? foreach("char_id_text_list") ?>
+  charass_alias<? literal("char_id_text_list") ?>.charass_value AS char<? literal("char_id_text_list") ?>,
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+  charass_alias<? literal("char_id_list_list") ?>.charass_value AS char<? literal("char_id_list_list") ?>,
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+  charass_alias<? literal("char_id_date_list") ?>.charass_value::date AS char<? literal("char_id_date_list") ?>,
+<? endforeach ?>
   cntct.*, addr.*
 FROM vendinfo 
   JOIN vendtype ON (vend_vendtype_id=vendtype_id)
   LEFT OUTER JOIN cntct ON (vend_cntct1_id=cntct_id) 
   LEFT OUTER JOIN addr ON (cntct_addr_id=addr_id) 
+<? foreach("char_id_text_list") ?>
+  LEFT OUTER JOIN charass charass_alias<? literal("char_id_text_list") ?> 
+       ON ((charass_alias<? literal("char_id_text_list") ?>.charass_target_type='V') 
+      AND  (charass_alias<? literal("char_id_text_list") ?>.charass_target_id=vend_id)
+      AND  (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=<? value("char_id_text_list") ?>))
+  LEFT OUTER JOIN char char_alias<? literal("char_id_text_list") ?> 
+       ON (charass_alias<? literal("char_id_text_list") ?>.charass_char_id=char_alias<? literal("char_id_text_list") ?>.char_id)
+<? endforeach ?>
+<? foreach("char_id_list_list") ?>
+  LEFT OUTER JOIN charass charass_alias<? literal("char_id_list_list") ?> 
+       ON ((charass_alias<? literal("char_id_list_list") ?>.charass_target_type='V') 
+      AND  (charass_alias<? literal("char_id_list_list") ?>.charass_target_id=vend_id)
+      AND  (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=<? value("char_id_list_list") ?>))
+  LEFT OUTER JOIN char char_alias<? literal("char_id_list_list") ?> 
+       ON (charass_alias<? literal("char_id_list_list") ?>.charass_char_id=char_alias<? literal("char_id_list_list") ?>.char_id)
+<? endforeach ?>
+<? foreach("char_id_date_list") ?>
+  LEFT OUTER JOIN charass charass_alias<? literal("char_id_date_list") ?> 
+       ON ((charass_alias<? literal("char_id_date_list") ?>.charass_target_type='V') 
+      AND  (charass_alias<? literal("char_id_date_list") ?>.charass_target_id=vend_id)
+      AND  (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=<? value("char_id_date_list") ?>))
+  LEFT OUTER JOIN char char_alias<? literal("char_id_date_list") ?> 
+       ON (charass_alias<? literal("char_id_date_list") ?>.charass_char_id=char_alias<? literal("char_id_date_list") ?>.char_id)
+<? endforeach ?>
 WHERE true
 <? if not exists("showInactive") ?> 
   AND vend_active 
@@ -63,4 +96,5 @@ WHERE true
 <? if exists("addr_country_pattern") ?>
   AND (COALESCE(addr_country,'') ~* <? value("addr_country_pattern") ?>)
 <? endif ?>
+<? literal("charClause") ?>
 ORDER BY vend_number; 
index 9677386..7863cfc 100644 (file)
@@ -7,7 +7,7 @@
 --            line item
 --              credit account
 --            debit account for entire order
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT orderid, seq,
index 6c839c4..e9d3f6b 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: voucherItem
 -- Name: distributions
 -- Notes: used by voucherItem
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT vodist_id, vodist_amount,
index b13fcd3..be5cc50 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: voucherItem
 -- Name: receipts
 -- Notes: used by voucherItem
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT recv_id AS item_id, 1 AS item_type, 'REC' AS action,
@@ -15,6 +15,7 @@ FROM recv
 WHERE ( (NOT recv_invoiced)
   AND   (recv_posted)
   AND   ((recv_vohead_id IS NULL) OR (recv_vohead_id=<? value("vohead_id") ?>))
+  AND   (recv_order_type='PO')
   AND   (recv_orderitem_id=<? value("poitem_id") ?>) )
 
 UNION
index a0b98f1..a3b05b2 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: voucherRegister
 -- Name: detail
 -- Notes: used by dspVoucherRegister
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT gltrans_id, gltrans_date,
index bb4a24b..18a7a93 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: whereUsed
 -- Name: detail
 -- Notes: used by dspSingleLevelWhereUsed, dspIndentedWhereUsed
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT <? if exists("byIndented") ?>
index 3beb70b..c7f8672 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: workOrderHistory
 -- Name: detail
 -- Notes: used by dspWoHistoryByNumber, dspWoHistoryByItem, dspWoHistoryByClassCode
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT
index b2a9edc..1bb6e0c 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: workOrderMaterial
 -- Name: detail
 -- Notes: used by dspWoMaterialsByItem, dspWoMaterialsByWorkOrder
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT womatl.*, formatWONumber(wo_id) AS wonumber, item_number,
index 2b3fcc2..350c6f4 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: workOrderSchedule
 -- Name:  detail
 -- Notes: 
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT wo_id,
index c6dd025..39c9b5d 100644 (file)
@@ -1,7 +1,7 @@
 -- Group: workOrderSchedule
 -- Name: parameterlist
 -- Notes: used by dspWoScheduleByParameterList
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT wo_id,
index 0f243c7..c1099da 100644 (file)
@@ -3,7 +3,7 @@
 -- Notes: used by dspMaterialUsageVarianceByBOMItem, dspMaterialUsageVarianceByComponentItem,
 --                dspMaterialUsageVarianceByItem, dspMaterialUsageVarianceByWarehouse,
 --                dspMaterialUsageVarianceByWorkOrder
--- Copyright (c) 1999-2012 by OpenMFG LLC, d/b/a xTuple.
+-- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
 -- See www.xtuple.com/CPAL for the full text of the software license.
 
 SELECT womatlvar_id, posted, 
index 315865b..64c89b5 100644 (file)
@@ -1,6 +1,4 @@
-
-SELECT dropIfExists('VIEW', 'cust', 'public', true);
-CREATE VIEW cust AS
+CREATE OR REPLACE VIEW cust AS
   SELECT cust_id, cust_active, cust_custtype_id, cust_salesrep_id,
         cust_commprcnt, cust_name,
         m.addr_line1 AS cust_address1,
index ecbbccd..39c8a83 100644 (file)
@@ -9,12 +9,16 @@ CREATE OR REPLACE VIEW ipsprice AS
          CASE WHEN (ipsitem_type='N') THEN (ipsitem_price * itemuomtouomratio(ipsitem_item_id, NULL, ipsitem_price_uom_id)) *
                                             iteminvpricerat(ipsitem_item_id)
               WHEN (ipsitem_type='D') THEN (item_listprice - (item_listprice * ipsitem_discntprcnt) - ipsitem_fixedamtdiscount)
+              WHEN ((ipsitem_type='M') AND fetchMetricBool('Long30Markups')) THEN
+               (stdCost(item_id) / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
               WHEN (ipsitem_type='M') THEN (item_listcost + (item_listcost * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
          END AS ipsprice_price,
          ipsitem_qtybreak AS ipsprice_uomqtybreak,
          ipsitem_qty_uom_id AS ipsprice_uomqtybreak_uom_id,
          CASE WHEN (ipsitem_type='N') THEN ipsitem_price
               WHEN (ipsitem_type='D') THEN (item_listprice - (item_listprice * ipsitem_discntprcnt) - ipsitem_fixedamtdiscount)
+              WHEN ((ipsitem_type='M') AND fetchMetricBool('Long30Markups')) THEN
+               (stdCost(item_id) / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
               WHEN (ipsitem_type='M') THEN (item_listcost + (item_listcost * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
          END AS ipsprice_uomprice,
          ipsitem_price_uom_id AS ipsprice_uomprice_uom_id,
@@ -29,11 +33,15 @@ CREATE OR REPLACE VIEW ipsprice AS
          item_id AS ipsprice_item_id,
          ipsitem_qtybreak AS ipsprice_qtybreak,
          CASE WHEN (ipsitem_type='D') THEN (item_listprice - (item_listprice * ipsitem_discntprcnt) - ipsitem_fixedamtdiscount)
+              WHEN ((ipsitem_type='M') AND fetchMetricBool('Long30Markups')) THEN
+               (stdCost(item_id) / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
               WHEN (ipsitem_type='M') THEN (item_listcost + (item_listcost * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
          END AS ipsprice_price,
          ipsitem_qtybreak AS ipsprice_uomqtybreak,
          item_inv_uom_id AS ipsprice_uomqtybreak_uom_id,
          CASE WHEN (ipsitem_type='D') THEN (item_listprice - (item_listprice * ipsitem_discntprcnt) - ipsitem_fixedamtdiscount)
+              WHEN ((ipsitem_type='M') AND fetchMetricBool('Long30Markups')) THEN
+               (stdCost(item_id) / (1.0 - ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
               WHEN (ipsitem_type='M') THEN (item_listcost + (item_listcost * ipsitem_discntprcnt) + ipsitem_fixedamtdiscount)
          END AS ipsprice_uomprice,
          item_price_uom_id AS ipsprice_uomprice_uom_id,