· 5 years ago · Feb 05, 2020, 04:02 PM
1-- CUSTOMERS BY FILE;
2-- ##############################################################################################
3DROP VIEW IF EXISTS cc_customersbyfileview CASCADE;
4
5
6-- FILES TRAFFIC: SEA;
7-- ##############################################################################################
8DROP VIEW IF EXISTS cc_filetrafficmar CASCADE;
9
10-- FILE VALORATION: SALE;
11-- ##############################################################################################
12DROP VIEW IF EXISTS cc_filevalsaleview CASCADE;
13
14-- FILE VALORATION: COST;
15-- ##############################################################################################
16DROP VIEW IF EXISTS cc_filevalpurchaseview CASCADE;
17
18-- FILE VALORATION PURCHASE: VENDORS BY FILE;
19-- ##############################################################################################
20DROP VIEW IF EXISTS cc_filevalpurchasevendorsbyfile CASCADE;
21
22-- FILE VALORATION PURCHASE: VENDORS BY SHIPMENT;
23-- ##############################################################################################
24DROP VIEW IF EXISTS cc_filevalpurchasevendorsbyshipment CASCADE;
25
26-- FILE VALORATION SALE: CUSTOMERS BY FILE;
27-- ##############################################################################################
28DROP VIEW IF EXISTS cc_filevalsalecustomersbyfile CASCADE;
29
30-- FILE VALORATION SALE: CUSTOMERS BY SHIPMENT;
31-- ##############################################################################################
32DROP VIEW IF EXISTS cc_filevalsalecustomersbyshipment CASCADE;
33
34-- UNLOCODES WITH MULTILANGUAGE;
35-- ##############################################################################################
36DROP VIEW IF EXISTS cc_unlocodeview CASCADE;
37
38-- CONTAINER LIST WITH WEIGHTS;
39-- ##############################################################################################
40DROP VIEW IF EXISTS cc_filetrafficcontainerview CASCADE;
41
42-- COMMODITIES LIST WITH LOADED VALUES;
43-- ##############################################################################################
44DROP VIEW IF EXISTS cc_shipmentcommview CASCADE;
45
46-- SHIPMENT COMMODITIES DETAIL BY CONTAINER;
47-- ##############################################################################################
48DROP VIEW IF EXISTS cc_shipmentbycontainerview CASCADE;
49
50-- SHIPMENT TRAFFIC MAR;
51-- ##############################################################################################
52DROP VIEW IF EXISTS cc_shipmenttrafficview CASCADE;
53
54-- FILE TRAFFIC CONTAINER VIEW 2;
55-- ##############################################################################################
56DROP VIEW IF EXISTS cc_filetrafficcontainerview2 CASCADE;
57
58-- PARTIES: SHIPPING LINES;
59-- ##############################################################################################
60DROP VIEW IF EXISTS cc_partyshippinglineview CASCADE;
61
62-- PARTIES: CONSOLIDATORS;
63-- ##############################################################################################
64DROP VIEW IF EXISTS cc_partyconsolidatorview CASCADE;
65
66-- PARTY ADDRESSES;
67-- ##############################################################################################
68DROP VIEW IF EXISTS cc_partyaddressview CASCADE;
69
70-- PARTIES;
71-- ##############################################################################################
72DROP VIEW IF EXISTS cc_partyview CASCADE;
73
74-- AIRLINES;
75-- ##############################################################################################
76DROP VIEW IF EXISTS cc_airlineview CASCADE;
77
78-- FILES TRAFFIC: AIR;
79-- ##############################################################################################
80DROP VIEW IF EXISTS cc_filetrafficair CASCADE;
81
82-- AIPORTS;
83-- ##############################################################################################
84DROP VIEW IF EXISTS cc_airportview CASCADE;
85
86-- COUNTRIES;
87-- ##############################################################################################
88DROP VIEW IF EXISTS cc_countryview CASCADE;
89
90-- FILE VAL CURRENCIES (FULL);
91-- ##############################################################################################
92DROP VIEW IF EXISTS cc_filevalcurrencyexchangeview CASCADE;
93
94-- SALE INVOICE HEADER;
95-- ##############################################################################################
96DROP VIEW IF EXISTS cc_saleinvoiceheaderview CASCADE;
97
98-- SHIPMENTS WITH VALORATION;
99-- ##############################################################################################
100DROP VIEW IF EXISTS cc_filevalsaleshipmentview CASCADE;
101
102-- PENDING VALORATIONS BY SHIPMENT;
103-- ##############################################################################################
104DROP VIEW IF EXISTS cc_filevalsalependingshipmentview CASCADE;
105
106-- INVOICE CONCEPTS VIEW;
107-- ##############################################################################################
108DROP VIEW IF EXISTS cc_invoiceconceptview CASCADE;
109
110-- SHIPMENTS;
111-- ##############################################################################################
112DROP VIEW IF EXISTS cc_shipmentview CASCADE;
113
114-- PARTY TYPES;
115-- ##############################################################################################
116DROP VIEW IF EXISTS cc_partytypeview CASCADE;
117
118-- SALE INVOICE HEADER PRINT;
119-- ##############################################################################################
120DROP VIEW IF EXISTS cc_saleinvoiceheaderprint CASCADE;
121
122-- SALE INVOICE DETAIL;
123-- ##############################################################################################
124DROP VIEW IF EXISTS cc_saleinvoicedetailview CASCADE;
125
126-- FILE DOCUMENT;
127-- ##############################################################################################
128DROP VIEW IF EXISTS cc_filedocumentview CASCADE;
129
130-- FILE ATTACHMENT;
131-- ##############################################################################################
132DROP VIEW IF EXISTS cc_fileattachmentview CASCADE;
133
134-- CONTACT EMAILS;
135-- ##############################################################################################
136DROP VIEW IF EXISTS cc_contactemailview CASCADE;
137
138-- INVOICE CONCEPTS FOR GROUPED INVOICES;
139-- ##############################################################################################
140DROP VIEW IF EXISTS cc_invoiceconceptgroupedview CASCADE;
141
142-- PROFIT;
143-- ##############################################################################################
144DROP VIEW IF EXISTS cc_profitview CASCADE;
145
146-- SALES REPRESENTATIVES;
147-- ##############################################################################################
148DROP VIEW IF EXISTS cc_salesrepresentativesview CASCADE;
149
150-- COURIER AGENTS;
151-- ##############################################################################################
152DROP VIEW IF EXISTS cc_courieragentview CASCADE;
153
154-- Transport places by shipment and file;
155-- ##############################################################################################
156DROP VIEW IF EXISTS cc_filetransportplacesview CASCADE;
157
158-- CUSTOMER BL TEXT;
159-- ##############################################################################################
160DROP VIEW IF EXISTS cc_bltextview CASCADE;
161
162-- AWB TEXT;
163-- ##############################################################################################
164DROP VIEW IF EXISTS cc_awbtextview CASCADE;
165
166-- PRINTERS VIEW;
167-- ##############################################################################################
168DROP VIEW IF EXISTS cc_printerview CASCADE;
169
170-- FILE TRAFFIC INLAND;
171-- ##############################################################################################
172DROP VIEW IF EXISTS cc_filetrafficland CASCADE;
173
174-- REPORTS;
175-- ##############################################################################################
176DROP VIEW IF EXISTS cc_reportview CASCADE;
177
178-- FILE TRAFIC COURIER;
179-- ##############################################################################################
180DROP VIEW IF EXISTS cc_filetrafficcour CASCADE;
181
182-- SHIPMENTS BY CONTAINER;
183-- ##############################################################################################
184DROP VIEW IF EXISTS cc_shipmentsbycontainerview CASCADE;
185
186-- GENERAL FILES;
187-- ##############################################################################################
188DROP VIEW IF EXISTS cc_shipmentgeneralview CASCADE;
189
190-- BOOKING CONTAINER HEADER - MESSAGE VIEW;
191-- ##############################################################################################
192DROP VIEW IF EXISTS cc_bookingcontainermessageview CASCADE;
193
194-- USER LOG VIEW;
195-- ##############################################################################################
196DROP VIEW IF EXISTS cc_userlogview CASCADE;
197
198-- MESSAGE EDI VIEW;
199-- ##############################################################################################
200DROP VIEW IF EXISTS cc_messageediview CASCADE;
201
202-- FILE TRAFFIC CONTAINER PORTIC TRACK AND TRACE;
203-- ##############################################################################################
204DROP VIEW IF EXISTS cc_filetrafficcontainerportictt CASCADE;
205
206-- OPEN SHIPMENTS;
207-- ##############################################################################################
208DROP VIEW IF EXISTS cc_shipmentopenview CASCADE;
209
210-- WAREHOUSE BY CONSOLIDATOR;
211-- ##############################################################################################
212DROP VIEW IF EXISTS cc_warehousebyconsolidatorview CASCADE;
213
214-- HANDLING AGENT BY AIRLINE;
215-- ##############################################################################################
216DROP VIEW IF EXISTS cc_handlingagentbyairlineview CASCADE;
217
218-- PENDINGARRIVALVIEW;
219-- ##############################################################################################
220DROP VIEW IF EXISTS cc_pendingarrivalview CASCADE;
221
222-- contacts;
223-- ##############################################################################################
224DROP VIEW IF EXISTS cc_contactview CASCADE;
225
226-- file val pending purchase;
227-- ##############################################################################################
228DROP VIEW IF EXISTS cc_filevalpurchasependingview CASCADE;
229
230-- SALE INVOICE PURCHASE;
231-- ##############################################################################################
232DROP VIEW IF EXISTS cc_purchaseinvoiceheaderview CASCADE;
233
234-- PURCHASE INVOICE DETAIL;
235-- ##############################################################################################
236DROP VIEW IF EXISTS cc_purchaseinvoicedetailview CASCADE;
237
238-- OPEN FILES;
239-- ##############################################################################################
240DROP VIEW IF EXISTS cc_fileopenview CASCADE;
241
242-- ACCOUNTING SUBACCOUNTS;
243-- ##############################################################################################
244DROP VIEW IF EXISTS cc_subaccountsplanview CASCADE;
245
246-- ACCOUNTING VIEW;
247-- ##############################################################################################
248DROP VIEW IF EXISTS cc_accountingplanview CASCADE;
249
250-- CUSTOMS ORDER VIEW;
251-- ##############################################################################################
252DROP VIEW IF EXISTS cc_customsorderview CASCADE;
253
254-- DEPARTMENT VIEW;
255-- ##############################################################################################
256DROP VIEW IF EXISTS cc_departmentview CASCADE;
257
258-- INCIDENT TYPE VIEW;
259-- ##############################################################################################
260DROP VIEW IF EXISTS cc_incidenttypeview CASCADE;
261
262-- INCIDENT SEVERITY LEVEL VIEW;
263-- ##############################################################################################
264DROP VIEW IF EXISTS cc_incidentseveritylevelview CASCADE;
265
266-- INCIDENT PROBABILITY VIEW;
267-- ##############################################################################################
268DROP VIEW IF EXISTS cc_incidentprobabilityview CASCADE;
269
270-- USER BY DEPARTMENT;
271-- ##############################################################################################
272DROP VIEW IF EXISTS cc_userbydepartmentview CASCADE;
273
274-- USERS BY DELEGATION;
275-- ##############################################################################################
276DROP VIEW IF EXISTS cc_usersbydelegationview CASCADE;
277
278-- RISK VECTORS;
279-- ##############################################################################################
280DROP VIEW IF EXISTS cc_riskvectorview CASCADE;
281
282-- RISK AFFECTATIONS;
283-- ##############################################################################################
284DROP VIEW IF EXISTS cc_riskaffectationview CASCADE;
285
286-- RISKS ;
287-- ##############################################################################################
288DROP VIEW IF EXISTS cc_riskview CASCADE;
289
290-- CORRECTIVE ACTIONS;
291-- ##############################################################################################
292DROP VIEW IF EXISTS cc_correctiveactionview CASCADE;
293
294-- INCIDENTS;
295-- ##############################################################################################
296DROP VIEW IF EXISTS cc_incidentview CASCADE;
297
298-- DELEGATION LEGAL TEXTS;
299-- ##############################################################################################
300DROP VIEW IF EXISTS cc_companylegaltextview CASCADE;
301
302-- USERS;
303-- ##############################################################################################
304DROP VIEW IF EXISTS cc_useraccessview CASCADE;
305
306-- USER DOCUMENTS;
307-- ##############################################################################################
308DROP VIEW IF EXISTS cc_userdocumentview CASCADE;
309
310-- DELEGATION DOCUMENTS;
311-- ##############################################################################################
312DROP VIEW IF EXISTS cc_delegationdocumentview CASCADE;
313
314-- COMPANY DOCUMENTS;
315-- ##############################################################################################
316DROP VIEW IF EXISTS cc_companydocumentview CASCADE;
317
318-- PARTY DOCUMENTS;
319-- ##############################################################################################
320DROP VIEW IF EXISTS cc_partydocumentview CASCADE;
321
322-- CORPORATE DOCUMENTS;
323-- ##############################################################################################
324DROP VIEW IF EXISTS cc_corporatedocuments CASCADE;
325
326-- PREVENTIVE ACTIONS;
327-- ##############################################################################################
328DROP VIEW IF EXISTS cc_preventiveactionview CASCADE;
329
330-- TRACK AND TRACE EVENTS;
331-- ##############################################################################################
332DROP VIEW IF EXISTS cc_trackandtraceeventview CASCADE;
333
334-- EDI NOTIFICATION;
335-- ##############################################################################################
336DROP VIEW IF EXISTS cc_delegationedinotificationview CASCADE;
337
338-- TRANSPORT ROUTES;
339-- ##############################################################################################
340DROP VIEW IF EXISTS cc_transportrouteview CASCADE;
341
342-- SHIPMENT TRAFFIC SEA;
343-- ##############################################################################################
344DROP VIEW IF EXISTS cc_shipmenttrafficmar CASCADE;
345
346-- SHIPMENT TRAFFIC AIR;
347-- ##############################################################################################
348DROP VIEW IF EXISTS cc_shipmenttrafficair CASCADE;
349
350-- SHIPMENT TRAFFIC LAND;
351-- ##############################################################################################
352DROP VIEW IF EXISTS cc_shipmenttrafficland CASCADE;
353
354-- SHIPMENT TRAFFIC COURIER;
355-- ##############################################################################################
356DROP VIEW IF EXISTS cc_shipmenttrafficcour CASCADE;
357
358-- MASTER VIEW;
359-- ##############################################################################################
360DROP VIEW IF EXISTS cc_masterview CASCADE;
361
362-- HOUSE VIEW;
363-- ##############################################################################################
364DROP VIEW IF EXISTS cc_houseview CASCADE;
365
366-- ACCOUNTING PROCESSES;
367-- ##############################################################################################
368DROP VIEW IF EXISTS cc_accountingprocessview CASCADE;
369
370-- TRANSPORT ROUTE ASSESSMENT;
371-- ##############################################################################################
372DROP VIEW IF EXISTS cc_transportrouteassessmentview CASCADE;
373
374-- TRANSPORT ROUTE ASSESSMENT GROUP;
375-- ##############################################################################################
376DROP VIEW IF EXISTS cc_transportrouteassessmentgroupview CASCADE;
377
378-- TRANSPORT ROUTE ASSESSMENT ANSWER;
379-- ##############################################################################################
380DROP VIEW IF EXISTS cc_transportrouteassessmentanswerview CASCADE;
381
382-- TRANSPORT ROUTE EVALUATION REPORT VIEW;
383-- ##############################################################################################
384DROP VIEW IF EXISTS cc_transportrouteevaluationview CASCADE;
385
386-- DOCUMENTARY STATUS;
387-- ##############################################################################################
388DROP VIEW IF EXISTS cc_documentarystatusview CASCADE;
389
390-- CUSTOMER MSOFT INTERFACE;
391-- ##############################################################################################
392DROP VIEW IF EXISTS cc_customermsoftview CASCADE;
393
394-- PROVIDER MSOFT INTERFACE;
395-- ##############################################################################################
396DROP VIEW IF EXISTS cc_providermsoftview CASCADE;
397
398-- TASK TYPES;
399-- ##############################################################################################
400DROP VIEW IF EXISTS cc_tasktypeview CASCADE;
401
402-- ##############################################################################################
403-- TASK TYPES;
404-- ##############################################################################################
405DROP VIEW IF EXISTS cc_taskview CASCADE;
406
407-- VISIT TYPES;
408-- ##############################################################################################
409DROP VIEW IF EXISTS cc_visittypeview CASCADE;
410
411-- VISITS;
412-- ##############################################################################################
413DROP VIEW IF EXISTS cc_visitview CASCADE;
414
415-- USERS BY DELEGATION;
416-- ##############################################################################################
417DROP VIEW IF EXISTS cc_userbydelegationview CASCADE;
418
419-- SEA CONTRACTS;
420-- ##############################################################################################
421DROP VIEW IF EXISTS cc_seacontractview CASCADE;
422
423-- TARIFF COST FREIGHT SEA;
424-- ##############################################################################################
425DROP VIEW IF EXISTS cc_tariffcostfreightseaview CASCADE;
426
427-- TARIFF COST FREIGHT SEA HISTO;
428-- ##############################################################################################
429DROP VIEW IF EXISTS cc_tariffcostfreightseahstview CASCADE;
430
431-- FREQUENCIES;
432-- ##############################################################################################
433DROP VIEW IF EXISTS cc_frequencyview CASCADE;
434
435-- TARIFF DICTIONARY;
436-- ##############################################################################################
437DROP VIEW IF EXISTS cc_tariffdictionaryview CASCADE;
438
439-- INVOICE CONCEPT TYPE;
440-- ##############################################################################################
441DROP VIEW IF EXISTS cc_invoiceconcepttypeview CASCADE;
442
443-- TARIFF COST SEA;
444-- ##############################################################################################
445DROP VIEW IF EXISTS cc_tariffcostsurchargeseaview CASCADE;
446
447-- TARIFF COST SEA HISTO;
448-- ##############################################################################################
449DROP VIEW IF EXISTS cc_tariffcostsurchargeseahstview CASCADE;
450
451-- TARIFF PRICE;
452-- ##############################################################################################
453DROP VIEW IF EXISTS cc_tariffpricesurchargeview CASCADE;
454
455-- TARIFF PRICE EXPENSE;
456-- ##############################################################################################
457DROP VIEW IF EXISTS cc_tariffcostexpenseseaview CASCADE;
458
459-- TARIFF PRICE EXPENSE HISTO;
460-- ##############################################################################################
461DROP VIEW IF EXISTS cc_tariffcostexpenseseahstview CASCADE;
462
463-- TARIFF COST SEA;
464-- ##############################################################################################
465DROP VIEW IF EXISTS cc_tariffcostseaview CASCADE;
466
467-- TARIFF COST SEA PRICE;
468-- ##############################################################################################
469DROP VIEW IF EXISTS cc_tariffcostseapriceview CASCADE;
470
471-- COMMERCIAL OFFER;
472-- ##############################################################################################
473DROP VIEW IF EXISTS cc_commercialofferview CASCADE;
474
475-- party address area detail view;
476-- ##############################################################################################
477DROP VIEW IF EXISTS cc_partyareadetailview CASCADE;
478
479-- TARIFF COST GENERAL;
480-- ##############################################################################################
481DROP VIEW IF EXISTS cc_tariffcostgeneralview CASCADE;
482
483-- TARIFF COST GENERAL HISTO;
484-- ##############################################################################################
485DROP VIEW IF EXISTS cc_tariffcostgeneralhstview CASCADE;
486
487-- SHIPPING LINES BY SHIPAGENT;
488-- ##############################################################################################
489DROP VIEW IF EXISTS cc_shippinglinebyshipagentsview CASCADE;
490
491-- COMMERCIAL OFFER SERVICE;
492-- ##############################################################################################
493DROP VIEW IF EXISTS cc_commercialofferserviceview CASCADE;
494
495-- LAND CARRIER DISTANCE HEADER;
496-- ##############################################################################################
497DROP VIEW IF EXISTS cc_landcarrierdistanceheaderview CASCADE;
498
499-- LAND CARRIER DISTANCE DETAIL;
500-- ##############################################################################################
501DROP VIEW IF EXISTS cc_landcarrierdistancedetailview CASCADE;
502
503-- COMMERCIAL POLICY HEADER VIEW;
504-- ##############################################################################################
505DROP VIEW IF EXISTS cc_commercialpolicyheaderview CASCADE;
506
507-- WAREHOUSE MOVEMENTS VIEW;
508-- ##############################################################################################
509DROP VIEW IF EXISTS cc_warehousemovementview CASCADE;
510
511-- WAREHOUSE MOVEMENTS TYPE VIEW;
512-- ##############################################################################################
513DROP VIEW IF EXISTS cc_warehousemovementtypeview CASCADE;
514
515-- WAREHOUSE PARKING AREA VIEW;
516-- ##############################################################################################
517DROP VIEW IF EXISTS cc_warehouseparkingview CASCADE;
518
519-- WAREHOUSE DOCK VIEW;
520-- ##############################################################################################
521DROP VIEW IF EXISTS cc_warehousedockview CASCADE;
522
523-- WAREHOUSE PARKING AREA VIEW;
524-- ##############################################################################################
525DROP VIEW IF EXISTS cc_warehouseparkingareaview CASCADE;
526
527-- WORK SHIFT VIEW;
528-- ##############################################################################################
529 DROP VIEW IF EXISTS cc_workshiftview CASCADE;
530
531-- WAREHOUSE MOVEMENTS TYPE VIEW;
532-- ##############################################################################################
533DROP VIEW IF EXISTS cc_warehousemovementfailedreasonview CASCADE;
534
535-- BANK;
536-- ##############################################################################################
537DROP VIEW IF EXISTS cc_bankview CASCADE;
538
539-- WAREHOUSE MOVEMENTS TYPE VIEW;
540-- ##############################################################################################
541DROP VIEW IF EXISTS cc_warehousemovementfailedreasonview CASCADE;
542
543-- CAPTUREBYCONTAINER VIEW;
544-- ##############################################################################################
545DROP VIEW IF EXISTS cc_capturebycontainerview CASCADE;
546
547-- ENTREGUESE VIEW;
548-- ##############################################################################################
549DROP VIEW IF EXISTS cc_entregueseview CASCADE;
550
551-- ADMITASE VIEW;
552-- ##############################################################################################
553DROP VIEW IF EXISTS cc_admitaseview CASCADE;
554
555-- INVOICES PENDING ACCOUNTING;
556-- ##############################################################################################
557DROP VIEW IF EXISTS cc_invoicespendingaccountingview CASCADE;
558
559-- COMMERCIAL OFFER FOOTERS;
560-- ##############################################################################################
561DROP VIEW IF EXISTS cc_commercialofferfooterview CASCADE;
562
563-- COMMERCIAL OFFER FOOTER DETAIL;
564-- ##############################################################################################
565DROP VIEW IF EXISTS cc_tarifftemplatedetailview CASCADE;
566
567-- COMMERCIAL OFFER EXPENSE PRICE;
568-- ##############################################################################################
569DROP VIEW IF EXISTS cc_commercialoffergeneralexpensepriceview CASCADE;
570
571-- TARIFF TEMPLATE HEADER LANG;
572-- ##############################################################################################
573DROP VIEW IF EXISTS cc_tarifftemplatelangview CASCADE;
574
575-- PARTY GROUP;
576-- ##############################################################################################
577DROP VIEW IF EXISTS cc_partygroupview CASCADE;
578
579-- TARIFF TEMPLATE HEADER LANG;
580-- ##############################################################################################
581DROP VIEW IF EXISTS cc_tarifftemplateview CASCADE;
582
583-- PARTY GROUP DETAIL;
584-- ##############################################################################################
585DROP VIEW IF EXISTS cc_partygroupdetailview CASCADE;
586
587-- PRINT LIST;
588-- ##############################################################################################
589DROP VIEW IF EXISTS cc_printlistview CASCADE;
590
591-- PRINT LIST HISTO;
592-- ##############################################################################################
593DROP VIEW IF EXISTS cc_printlisthistoview CASCADE;
594
595-- BASF FILE;
596-- ##############################################################################################
597DROP VIEW IF EXISTS cc_basffileview CASCADE;
598
599-- BASF SHIPMENT;
600-- ##############################################################################################
601DROP VIEW IF EXISTS cc_basfshipmentview CASCADE;
602
603-- cc_filegeneralview;
604-- ##############################################################################################
605DROP VIEW IF EXISTS cc_filegeneralview CASCADE;
606
607-- SPECIAL HANDLING CODES;
608-- ##############################################################################################
609DROP VIEW IF EXISTS cc_specialhandlingcodeview CASCADE;
610
611-- AWB SPECIAL HANDLING CODES;
612-- ##############################################################################################
613DROP VIEW IF EXISTS cc_awbspecialhandlingview CASCADE;
614
615-- SALE INVOICE DUE DATES AE VIEW;
616-- ##############################################################################################
617DROP VIEW IF EXISTS cc_saleinvoiceduedatea3view CASCADE;
618
619-- SALE INVOICE DUE DATES AE VIEW;
620-- ##############################################################################################
621DROP VIEW IF EXISTS cc_purchaseinvoiceduedatea3view CASCADE;
622
623-- GROUP SHIPMENT TRAFFIC;
624-- ##############################################################################################
625DROP VIEW IF EXISTS cc_shipmenttrafficairgroupedview CASCADE;
626
627-- FILE WITH GRM SYNCHRONIZE STATUS IS ERROR;
628-- ##############################################################################################
629DROP VIEW IF EXISTS cc_filegrmerror CASCADE;
630
631-- SHIPMENT WITH GRM SYNCHRONIZE STATUS IS ERROR;
632-- ##############################################################################################
633DROP VIEW IF EXISTS cc_shipmentgrmerror CASCADE;
634
635-- FILE TRAFFIC CONTAINER WITH GRM SYNCHRONIZE STATUS IS ERROR;
636-- ##############################################################################################
637DROP VIEW IF EXISTS cc_filetrafficcontainergrmerror CASCADE;
638
639-- SALE INVOICES WITH GRM SYNCHRONIZE STATUS IS ERROR;
640-- ##############################################################################################
641DROP VIEW IF EXISTS cc_saleinvoicegrmerror CASCADE;
642
643-- PARTY EVALUATION GDP VIEW ;
644-- ##############################################################################################
645DROP VIEW IF EXISTS cc_partyevaluationgdpview CASCADE;
646
647-- COMMERCIAL OFFER PROFIT ;
648-- ##############################################################################################
649DROP VIEW IF EXISTS cc_commercialofferprofitview CASCADE;
650
651-- ORIGINAL DOCUMENT LETTER CONFIGURATION ;
652-- ##############################################################################################
653DROP VIEW IF EXISTS cc_originaldocumentletterconfheaderview CASCADE;
654
655-- BUSQUEDA DE CONTENEDOR CON ENTREGUSE;
656-- ##############################################################################################
657DROP VIEW IF EXISTS cc_oldestcontainerforentregueseview CASCADE;
658
659-- BUSQUEDA DE CONTENEDOR CON ADMITASE;
660-- ##############################################################################################
661DROP VIEW IF EXISTS cc_oldestcontainerforadmitaseview CASCADE;
662
663-- CONTACT TYPE ;
664-- ##############################################################################################
665DROP VIEW IF EXISTS cc_contacttypeview CASCADE;
666
667-- PARTY CERTIFICATION TYPE ;
668-- ##############################################################################################
669DROP VIEW IF EXISTS cc_partycertificationtypeview CASCADE;
670
671-- PARTY CERTIFICATION TYPE;
672-- ##############################################################################################
673DROP VIEW IF EXISTS cc_partycertificationview CASCADE;
674
675-- PARTY CERTIFICATION TYPE;
676-- ##############################################################################################
677DROP VIEW IF EXISTS cc_activityview CASCADE;
678
679-- SHIPMENT ENTRIES;
680-- ##############################################################################################
681DROP VIEW IF EXISTS cc_shipmententryview CASCADE;
682
683-- BL PAYMENT TYPE ID ;
684-- ##############################################################################################
685DROP VIEW IF EXISTS cc_blpaymenttypeview CASCADE;
686
687-- CONTAINER BLANKET TYPE;
688-- ##############################################################################################
689DROP VIEW IF EXISTS cc_containerblankettypeview CASCADE;
690
691-- SQL SENTENCES ;
692-- ##############################################################################################
693DROP VIEW IF EXISTS cc_sqlsentenceview CASCADE;
694
695-- PARTY SALE TARIFFS ;
696-- ##############################################################################################
697DROP VIEW IF EXISTS cc_partysaletariffview CASCADE;
698
699-- PROCESSES ;
700-- ##############################################################################################
701DROP VIEW IF EXISTS cc_processheaderview CASCADE;
702
703ALTER TABLE cc_tariffprice
704 ALTER COLUMN percentage type numeric(19, 5);
705
706-- CUSTOMERS BY FILE;
707-- ##############################################################################################
708CREATE OR REPLACE VIEW cc_customersbyfileview AS
709 SELECT f.id,
710 f.name,
711 ( SELECT array_to_string(ARRAY( SELECT DISTINCT COALESCE(pa.name, COALESCE(p.name_short, p.name)) AS "coalesce"
712 FROM cc_shipment shp
713 LEFT JOIN cc_partyaddress pa ON pa.id = shp.customer_id
714 LEFT JOIN cc_party p ON p.id = pa.party_id
715 WHERE shp.file_id = f.id), ','::text, '*'::text) AS array_to_string) AS customernames
716 FROM cc_file f;
717
718
719-- FILES TRAFFIC: SEA
720-- ##############################################################################################
721CREATE OR REPLACE VIEW cc_filetrafficmar AS
722 SELECT f.delegation_id,
723 f.isactive,
724 ft.id,
725 ft.file_id,
726 ft.transportmode,
727 ft.trafficflow,
728 ves.name AS vesselname,
729 ft.origin_id,
730 ft.destination_id,
731 ft.shippingline_id,
732 ft.shipagent_id,
733 ft.correspondent_id,
734 ft.warehouse_id,
735 ft.consolidator_id,
736 f.name,
737 fs.numcont,
738 ft.trafficchargetype,
739 ft.etd,
740 ft.eta,
741 COALESCE(oril.name, ori.name) AS origin,
742 COALESCE(desl.name, des.name) AS destination,
743 f.status,
744 oril.language_id AS orilanguage_id,
745 desl.language_id AS deslanguage_id,
746 fs.customername,
747 fs.customerref,
748 fs.containerplate,
749 fs.numshipments,
750 fs.isdangerous,
751 fs.istemperaturecontrol,
752 ft.portcall,
753 ft.bookingnumber,
754 ft.blnumber,
755 ft.direct,
756 fs2.isrisk,
757 fs2.isincident,
758 fs2.statusinvpurchase,
759 fs2.statusinvsale,
760 f.isfile,
761 f.grmsyncstatus,
762 f.risponsable_id,
763 f.docrisponsable_id
764 , u1.name as risponsablename
765, u2.name as docrisponsablename
766, ft.freightcontrolled, fs.iscontainerblanket, fs.iscontainerflexi, fs.isdocumentaircargomanifest, fs.isdocumentbooking, fs.isdocumentmawb, fs.isdocumentshippinginstructions, fs.isdocumentshippingmanifest, fs.isdocumenttransportcontainer
767 FROM cc_file f
768 LEFT JOIN cc_filetraffic ft ON ft.file_id = f.id
769 LEFT JOIN cc_filetrafficsummary fs ON fs.filetraffic_id = ft.id
770 LEFT JOIN cc_filesummary fs2 ON fs2.file_id = f.id
771 LEFT JOIN cc_unlocode ori ON ori.id = ft.origin_id
772 LEFT JOIN cc_unlocodelang oril ON oril.unlocode_id = ori.id
773 LEFT JOIN cc_unlocode des ON des.id = ft.destination_id
774 LEFT JOIN cc_unlocodelang desl ON desl.unlocode_id = des.id
775 LEFT JOIN cc_vessel ves ON ves.id = ft.vessel_id
776 LEFT JOIN cc_useraccess u1 on u1.id = f.risponsable_id
777 LEFT JOIN cc_useraccess u2 on u2.id = f.docrisponsable_id
778 WHERE ft.transportmode::text = 'SEA'::text;
779
780-- FILE VALORATION: SALE;
781-- ##############################################################################################
782CREATE OR REPLACE VIEW cc_filevalsaleview AS
783 SELECT del.id AS delegation_id,
784 conl.language_id,
785 val.id,
786 con.id AS invoiceconcept_id,
787 conl.name AS invoiceconceptname,
788 fil.name AS filename,
789 ftr.trafficflow,
790 shp.name AS shipmentname,
791 val.customer_id,
792 val.isinvoice,
793 val.printtext,
794 COALESCE(pac.name, COALESCE(pc.name_short, pc.name)) AS customername,
795 COALESCE(val.units, 1::numeric) AS units,
796 COALESCE(val.price, 0::numeric) AS price,
797 cur.code AS currencycode,
798 cur.decimals AS currencydecimals,
799 cur.symbol AS currencysymbol,
800
801 CASE
802 WHEN COALESCE(sd.currency_id, val.currency_id) = del.currency_id THEN 1::numeric
803 ELSE COALESCE(
804 CASE
805 WHEN sh.currency_id = del.currency_id THEN sd.exchange
806 ELSE NULL::numeric
807 END, COALESCE(sh.exchange, COALESCE(sce.exchange, COALESCE(exc.exchangesale, COALESCE(cex.exchange, COALESCE(( SELECT cex_1.exchange
808 FROM cc_currencyexchange cex_1
809 WHERE cex_1.currencyfrom_id = COALESCE(sd.currency_id, val.currency_id) AND cex_1.currencyto_id = del.currency_id AND cex_1.exchangedate::date <= COALESCE(COALESCE(shr.invoicedate, sh.invoicedate), COALESCE(fil.datecreation, fil2.datecreation))::date
810 ORDER BY cex_1.exchangedate DESC
811 LIMIT 1), 1::numeric))))))
812 END AS exchange,
813
814
815 COALESCE(sd.currency_id, val.currency_id) as currency_id,
816 COALESCE(fil.id, shp.file_id) AS file_id,
817 shp.id AS shipment_id,
818 cong.printorder AS grouporder,
819 cont.printorder AS typeorder,
820 con.printorder AS conceptorder,
821 CASE
822 WHEN COALESCE(con.isfavourite, 'N'::bpchar) = 'Y'::bpchar THEN 0
823 ELSE 1
824 END AS isfavourite,
825 round(COALESCE(val.units, 1::numeric) * COALESCE(val.price, 0::numeric), COALESCE(curd.decimals, 2)) AS amount,
826 round(COALESCE(val.units, 1::numeric) * COALESCE(val.price, 0::numeric) *
827 CASE
828 WHEN COALESCE(sd.currency_id, val.currency_id) = del.currency_id THEN 1::numeric
829 ELSE COALESCE(
830 CASE
831 WHEN sh.currency_id = del.currency_id THEN sd.exchange
832 ELSE NULL::numeric
833 END, COALESCE(sh.exchange, COALESCE(sce.exchange, COALESCE(exc.exchangesale, COALESCE(cex.exchange, COALESCE(( SELECT cex_1.exchange
834 FROM cc_currencyexchange cex_1
835 WHERE cex_1.currencyfrom_id = COALESCE(sd.currency_id, val.currency_id) AND cex_1.currencyto_id = del.currency_id AND cex_1.exchangedate::date <= COALESCE(COALESCE(shr.invoicedate, sh.invoicedate), COALESCE(fil.datecreation, fil2.datecreation))::date
836 ORDER BY cex_1.exchangedate DESC
837 LIMIT 1), 1::numeric))))))
838 END, COALESCE(curd.decimals, 2)) AS amountfinal,
839 cont.isoutlayvat,
840 CASE WHEN sd.id IS NOT NULL THEN sd.invoicetax_id ELSE val.invoicetax_id END as invoicetax_id,
841 itl.name AS invoicetaxname,
842 sh.name AS saleinvoicename,
843 sh.iscompleted,
844 sh.id AS saleinvoice_id,
845 COALESCE(pac2.name, COALESCE(pc2.name_short, pc2.name)) AS invoicecustomername,
846 val.comments AS valcomments,
847 sh.commentsinternal AS invcomments,
848 sh.accountingstatus,
849 CASE
850 WHEN COALESCE(fil2.filetype, fil.filetype)::text = 'TRA'::text AND ftr.trafficflow::text = 'I'::text THEN ftr.eta
851 WHEN COALESCE(fil2.filetype, fil.filetype)::text = 'TRA'::text THEN ftr.etd
852 WHEN COALESCE(fil2.filetype, fil.filetype)::text = 'GEN'::text THEN fg.servicedate
853 ELSE COALESCE(fil2.datecreation, fil.datecreation)
854 END AS servicedate
855 , val.incident_id, val.containertype_id, COALESCE(cnt.name_short, cnt.name) as containertypename, cnt.printorder as containerprintorder
856 FROM cc_filevalsale val
857 LEFT JOIN cc_invoiceconcept con ON con.id = val.invoiceconcept_id
858 LEFT JOIN cc_invoiceconceptlang conl ON conl.parent_id = con.id
859 LEFT JOIN cc_invoiceconceptgroup cong ON cong.id = con.invoiceconceptgroup_id
860 LEFT JOIN cc_invoiceconcepttype cont ON cont.id = con.invoiceconcepttype_id
861 LEFT JOIN cc_file fil ON fil.id = val.file_id
862 LEFT JOIN cc_shipment shp ON shp.id = val.shipment_id
863 LEFT JOIN cc_file fil2 ON fil2.id = shp.file_id
864 LEFT JOIN cc_filetraffic ftr ON ftr.file_id = COALESCE(fil2.id, fil.id)
865 LEFT JOIN cc_filegeneral fg ON fg.file_id = COALESCE(fil2.id, fil.id)
866 LEFT JOIN cc_partyaddress pac ON pac.id = val.customer_id
867 LEFT JOIN cc_party pc ON pc.id = pac.party_id
868 LEFT JOIN cc_saleinvoicedetail sd ON sd.filevalsale_id = val.id
869 LEFT JOIN cc_currency cur ON cur.id = COALESCE(sd.currency_id, val.currency_id)
870 LEFT JOIN cc_delegation del ON del.id = COALESCE(fil2.delegation_id, fil.delegation_id)
871 LEFT JOIN cc_currency curd ON curd.id = del.currency_id
872 LEFT JOIN cc_filevalcurrencyexchange exc ON exc.file_id = COALESCE(val.file_id, shp.file_id) AND exc.currencyfrom_id = COALESCE(sd.currency_id, val.currency_id) AND exc.currencyto_id = del.currency_id
873 LEFT JOIN cc_invoicetaxlang itl ON itl.parent_id = CASE WHEN sd.id IS NOT NULL THEN sd.invoicetax_id ELSE val.invoicetax_id END AND itl.language_id = conl.language_id
874 LEFT JOIN cc_saleinvoiceheader sh ON sh.id = sd.parent_id
875 LEFT JOIN cc_saleinvoiceheader shr ON shr.id = sh.referencedinvoice_id
876 LEFT JOIN cc_saleinvoicecurrencyexchange sce ON sce.saleinvoiceheader_id = sd.parent_id AND sce.currencyfrom_id = COALESCE(sd.currency_id, val.currency_id) AND sh.currency_id = del.currency_id
877 LEFT JOIN cc_currencyexchange cex ON cex.currencyfrom_id = COALESCE(sd.currency_id, val.currency_id) AND cex.currencyto_id = del.currency_id AND cex.exchangedate::date = COALESCE(COALESCE(shr.invoicedate, sh.invoicedate), COALESCE(fil.datecreation, fil2.datecreation))::date
878 LEFT JOIN cc_partyaddress pac2 ON pac2.id = sh.customer_id
879 LEFT JOIN cc_party pc2 ON pc2.id = pac2.party_id
880 LEFT JOIN cc_containertype cnt on cnt.id = val.containertype_id;
881
882ALTER TABLE cc_filevalsaleview
883 OWNER TO postgres;
884
885
886-- FILE VALORATION: COST;
887-- ##############################################################################################
888CREATE OR REPLACE VIEW cc_filevalpurchaseview AS
889 SELECT del.id AS delegation_id,
890 conl.language_id,
891 val.id,
892 val.senttogrm,
893 val.saleInvoiceIdAssociated,
894 con.id AS invoiceconcept_id,
895 CASE WHEN val.printtext IS NOT NULL AND length(trim(val.printtext)) > 0 THEN val.printtext ELSE conl.name END AS invoiceconceptname,
896 fil.name AS filename,
897 shp.name AS shipmentname,
898 val.vendor_id,
899 COALESCE(pac.name, COALESCE(pc.name_short, pc.name)) AS vendorname,
900 COALESCE(val.units, 1::numeric) AS units,
901 COALESCE(val.price, 0::numeric) AS price,
902 cur.code AS currencycode,
903 cur.decimals AS currencydecimals,
904 cur.symbol AS currencysymbol,
905 COALESCE(ph.exchange, COALESCE(exc.exchangecost, COALESCE(cex.exchange, COALESCE(( SELECT cex_1.exchange
906 FROM cc_currencyexchange cex_1
907 WHERE cex_1.currencyfrom_id = COALESCE(pd.currency_id, val.currency_id) AND cex_1.currencyto_id = del.currency_id AND cex_1.exchangedate::date <=
908 CASE
909 WHEN COALESCE(fil2.filetype, fil.filetype)::text = 'GEN'::text THEN fg.servicedate
910 WHEN ftr.trafficflow IS NOT NULL AND ftr.trafficflow::text = 'I'::text THEN ftr.eta
911 ELSE ftr.etd
912 END::date
913 ORDER BY cex_1.exchangedate DESC
914 LIMIT 1), 1::numeric)))) AS exchange,
915 COALESCE(pd.currency_id, val.currency_id) as currency_id,
916 COALESCE(fil.id, shp.file_id) AS file_id,
917 shp.id AS shipment_id,
918 cong.printorder AS grouporder,
919 cont.printorder AS typeorder,
920 con.printorder AS conceptorder,
921 CASE
922 WHEN COALESCE(con.isfavourite, 'N'::bpchar) = 'Y'::bpchar THEN 0
923 ELSE 1
924 END AS isfavourite,
925 round(COALESCE(val.units, 1::numeric) * COALESCE(val.price, 0::numeric), COALESCE(curd.decimals, 2)) AS amount,
926 round(COALESCE(val.units, 1::numeric) * COALESCE(val.price, 0::numeric) *
927
928COALESCE(ph.exchange, COALESCE(exc.exchangecost, COALESCE(cex.exchange, COALESCE(( SELECT cex_1.exchange
929 FROM cc_currencyexchange cex_1
930 WHERE cex_1.currencyfrom_id = COALESCE(pd.currency_id, val.currency_id) AND cex_1.currencyto_id = del.currency_id AND cex_1.exchangedate::date <=
931 CASE
932 WHEN COALESCE(fil2.filetype, fil.filetype)::text = 'GEN'::text THEN fg.servicedate
933 WHEN ftr.trafficflow IS NOT NULL AND ftr.trafficflow::text = 'I'::text THEN ftr.eta
934 ELSE ftr.etd
935 END::date
936 ORDER BY cex_1.exchangedate DESC
937 LIMIT 1), 1::numeric))))
938
939 , COALESCE(curd.decimals, 2)) AS amountfinal,
940 cont.isoutlayvat,
941 val.isinvoice,
942 CASE
943 WHEN val.isinvoice = 'N'::bpchar AND pd.id IS NOT NULL THEN 'Y'::text
944 ELSE 'N'::text
945 END AS partialpaid,
946 CASE WHEN pd.id IS NOT NULL THEN pd.invoicetax_id ELSE val.invoicetax_id END as invoicetax_id,
947 itl.name AS invoicetaxname,
948 ftr.trafficflow,
949 ph.name AS purchaseinvoicename,
950 ph.iscompleted,
951 ph.id AS purchaseinvoice_id,
952 COALESCE(pac2.name, COALESCE(pc2.name_short, pc2.name)) AS invoiceprovidername,
953 pd.currency_id AS invcurrency_id,
954 pd.units AS invunits,
955 pd.price AS invprice,
956 pd.exchange AS invexchange,
957 CASE
958 WHEN pd.id IS NOT NULL THEN round(COALESCE(pd.units, 1::numeric) * COALESCE(pd.price, 0::numeric), COALESCE(curinv.decimals, 2))
959 ELSE NULL::numeric
960 END AS invamount,
961 CASE
962 WHEN pd.id IS NOT NULL THEN round(COALESCE(pd.units, 1::numeric) * COALESCE(pd.price, 0::numeric) *
963 CASE
964 WHEN ph.currency_id = pd.currency_id AND pd.currency_id <> del.currency_id AND ph.exchange IS NOT NULL THEN ph.exchange
965 WHEN ph.currency_id = del.currency_id AND pd.currency_id <> del.currency_id AND pd.exchange IS NOT NULL THEN pd.exchange
966 ELSE COALESCE(exc.exchangecost, COALESCE(cexi.exchange, COALESCE(( SELECT cexi_1.exchange
967 FROM cc_currencyexchange cexi_1
968 WHERE cexi_1.currencyfrom_id = pd.currency_id AND cexi_1.currencyto_id = del.currency_id AND cexi_1.exchangedate::date <=
969 CASE
970 WHEN COALESCE(fil2.filetype, fil.filetype)::text = 'GEN'::text THEN fg.servicedate
971 WHEN ftr.trafficflow IS NOT NULL AND ftr.trafficflow::text = 'I'::text THEN ftr.eta
972 ELSE ftr.etd
973 END::date
974 ORDER BY cex.exchangedate DESC
975 LIMIT 1), 1::numeric)))
976 END, COALESCE(curinv.decimals, 2))
977 ELSE NULL::numeric
978 END AS invamountfinal,
979 curinv.code AS invcurrencycode,
980 curinv.decimals AS invcurrencydecimals,
981 curinv.symbol AS invcurrencysymbol,
982 val.comments AS valcomments,
983 ph.commentsinternal AS invcomments,
984 ph.accountingstatus, val.incident_id, pro.accountingprovidertype, val.containertype_id, COALESCE(cnt.name_short, cnt.name) as containertypename, cnt.printorder as containerprintorder
985 FROM cc_filevalpurchase val
986 LEFT JOIN cc_language lang ON lang.isactive = 'Y'::bpchar
987 LEFT JOIN cc_invoiceconcept con ON con.id = val.invoiceconcept_id
988 LEFT JOIN cc_invoiceconceptlang conl ON conl.parent_id = con.id AND conl.language_id = lang.id
989 LEFT JOIN cc_invoiceconceptgroup cong ON cong.id = con.invoiceconceptgroup_id
990 LEFT JOIN cc_invoiceconcepttype cont ON cont.id = con.invoiceconcepttype_id
991 LEFT JOIN cc_file fil ON fil.id = val.file_id
992 LEFT JOIN cc_shipment shp ON shp.id = val.shipment_id
993 LEFT JOIN cc_file fil2 ON fil2.id = shp.file_id
994 LEFT JOIN cc_filetraffic ftr ON ftr.file_id = COALESCE(fil2.id, fil.id)
995 LEFT JOIN cc_filegeneral fg ON fg.file_id = COALESCE(fil2.id, fil.id)
996 LEFT JOIN cc_partyaddress pac ON pac.id = val.vendor_id
997 LEFT JOIN cc_party pc ON pc.id = pac.party_id
998 LEFT JOIN cc_purchaseinvoicedetail pd ON pd.filevalpurchase_id = val.id
999 LEFT JOIN cc_invoicetaxlang itl ON itl.parent_id = CASE WHEN pd.id IS NOT NULL THEN pd.invoicetax_id ELSE val.invoicetax_id END AND itl.language_id = lang.id
1000 LEFT JOIN cc_purchaseinvoiceheader ph ON ph.id = pd.parent_id
1001 LEFT JOIN cc_partyaddress pac2 ON pac2.id = ph.vendor_id
1002 LEFT JOIN cc_party pc2 ON pc2.id = pac2.party_id
1003 LEFT JOIN cc_provider pro on pro.party_id = COALESCE(pc2.id, pc.id)
1004 LEFT JOIN cc_currency cur ON cur.id = COALESCE(pd.currency_id, val.currency_id)
1005 LEFT JOIN cc_delegation del ON del.id = COALESCE(fil2.delegation_id, fil.delegation_id)
1006 LEFT JOIN cc_currency curd ON curd.id = del.currency_id
1007 LEFT JOIN cc_currency curinv ON curinv.id = pd.currency_id
1008 LEFT JOIN cc_filevalcurrencyexchange exc ON exc.file_id = COALESCE(val.file_id, shp.file_id) AND exc.currencyfrom_id = COALESCE(pd.currency_id, val.currency_id) AND exc.currencyto_id = del.currency_id
1009 LEFT JOIN cc_currencyexchange cex ON cex.currencyfrom_id = COALESCE(pd.currency_id, val.currency_id) AND cex.currencyto_id = del.currency_id AND cex.exchangedate::date =
1010 CASE
1011 WHEN COALESCE(fil2.filetype, fil.filetype)::text = 'GEN'::text THEN fg.servicedate
1012 WHEN ftr.trafficflow IS NOT NULL AND ftr.trafficflow::text = 'I'::text THEN ftr.eta
1013 ELSE ftr.etd
1014 END::date
1015 LEFT JOIN cc_currencyexchange cexi ON cexi.currencyfrom_id = pd.currency_id AND cexi.currencyto_id = del.currency_id AND cexi.exchangedate::date =
1016 CASE
1017 WHEN COALESCE(fil2.filetype, fil.filetype)::text = 'GEN'::text THEN fg.servicedate
1018 WHEN ftr.trafficflow IS NOT NULL AND ftr.trafficflow::text = 'I'::text THEN ftr.eta
1019 ELSE ftr.etd
1020 END::date
1021 LEFT JOIN cc_containertype cnt on cnt.id = val.containertype_id;
1022
1023
1024-- FILE VALORATION PURCHASE: VENDORS BY FILE;
1025-- ##############################################################################################
1026CREATE OR REPLACE VIEW cc_filevalpurchasevendorsbyfile AS
1027 SELECT COALESCE(val.file_id, fil.id) AS file_id,
1028 val.vendor_id,
1029 COALESCE(pa.name, COALESCE(p.name_short, p.name)) AS vendor_name
1030 FROM cc_filevalpurchase val
1031 LEFT JOIN cc_partyaddress pa ON pa.id = val.vendor_id
1032 LEFT JOIN cc_party p ON p.id = pa.party_id
1033 LEFT JOIN cc_shipment shp ON shp.id = val.shipment_id
1034 LEFT JOIN cc_file fil ON fil.id = shp.file_id
1035 GROUP BY COALESCE(val.file_id, fil.id), val.vendor_id, COALESCE(pa.name, COALESCE(p.name_short, p.name))
1036 ORDER BY COALESCE(val.file_id, fil.id), val.vendor_id, COALESCE(pa.name, COALESCE(p.name_short, p.name));
1037
1038-- FILE VALORATION PURCHASE: VENDORS BY SHIPMENT;
1039-- ##############################################################################################
1040CREATE OR REPLACE VIEW cc_filevalpurchasevendorsbyshipment AS
1041 SELECT val.shipment_id,
1042 val.vendor_id,
1043 COALESCE(pa.name, COALESCE(p.name_short, p.name)) AS vendor_name
1044 FROM cc_filevalpurchase val
1045 LEFT JOIN cc_partyaddress pa ON pa.id = val.vendor_id
1046 LEFT JOIN cc_party p ON p.id = pa.party_id
1047 LEFT JOIN cc_shipment shp ON shp.id = val.shipment_id
1048 GROUP BY val.shipment_id, val.vendor_id, COALESCE(pa.name, COALESCE(p.name_short, p.name))
1049 ORDER BY val.shipment_id, val.vendor_id, COALESCE(pa.name, COALESCE(p.name_short, p.name));
1050
1051-- FILE VALORATION SALE: CUSTOMERS BY FILE;
1052-- ##############################################################################################
1053CREATE OR REPLACE VIEW cc_filevalsalecustomersbyfile AS
1054 SELECT COALESCE(val.file_id, fil.id) AS file_id,
1055 val.customer_id,
1056 COALESCE(pa.name, COALESCE(p.name_short, p.name)) AS customer_name
1057 FROM cc_filevalsale val
1058 LEFT JOIN cc_partyaddress pa ON pa.id = val.customer_id
1059 LEFT JOIN cc_party p ON p.id = pa.party_id
1060 LEFT JOIN cc_shipment shp ON shp.id = val.shipment_id
1061 LEFT JOIN cc_file fil ON fil.id = shp.file_id
1062 GROUP BY COALESCE(val.file_id, fil.id), val.customer_id, COALESCE(pa.name, COALESCE(p.name_short, p.name))
1063 ORDER BY COALESCE(val.file_id, fil.id), val.customer_id, COALESCE(pa.name, COALESCE(p.name_short, p.name));
1064
1065
1066-- FILE VALORATION SALE: CUSTOMERS BY SHIPMENT;
1067-- ##############################################################################################
1068CREATE OR REPLACE VIEW cc_filevalsalecustomersbyshipment AS
1069 SELECT val.shipment_id,
1070 val.customer_id,
1071 COALESCE(pa.name, COALESCE(p.name_short, p.name)) AS customer_name
1072 FROM cc_filevalsale val
1073 LEFT JOIN cc_partyaddress pa ON pa.id = val.customer_id
1074 LEFT JOIN cc_party p ON p.id = pa.party_id
1075 LEFT JOIN cc_shipment shp ON shp.id = val.shipment_id
1076 GROUP BY val.shipment_id, val.customer_id, COALESCE(pa.name, COALESCE(p.name_short, p.name))
1077 ORDER BY val.shipment_id, val.customer_id, COALESCE(pa.name, COALESCE(p.name_short, p.name));
1078
1079
1080-- UNLOCODES WITH MULTILANGUAGE;
1081-- ##############################################################################################
1082CREATE OR REPLACE VIEW cc_unlocodeview AS
1083 SELECT u.id,
1084 u.code,
1085 u.country_id,
1086 u.isport,
1087 u.isairport,
1088 u.istrain,
1089 u.island,
1090 u.ismail,
1091 l.language_id,
1092 u.isfrontier,
1093 COALESCE(u.name, l.name) AS name,
1094 COALESCE(coul.name, cou.name) AS countryname,
1095 COALESCE(sub.name, u.locationsubdivisioncode) AS locationsubdivisionname, u.numberofusages
1096 FROM cc_unlocode u
1097 LEFT JOIN cc_unlocodelang l ON l.unlocode_id = u.id
1098 LEFT JOIN cc_countrylang coul ON coul.country_id = u.country_id AND coul.language_id = l.language_id
1099 LEFT JOIN cc_country cou ON cou.id = u.country_id
1100 LEFT JOIN cc_locationsubdivision sub ON sub.id = u.locationsubdivision_id;
1101
1102-- CONTAINER LIST WITH WEIGHTS;
1103-- ##############################################################################################
1104CREATE OR REPLACE VIEW cc_filetrafficcontainerview AS
1105 SELECT f.delegation_id, cnt.id,
1106 cnt.filetraffic_id,
1107 cnt.containerid,
1108 cnt.bookingcontainerheader_id,
1109 cnt.containerplate,
1110 cnt.containertype_id,
1111 CASE WHEN cntt.name_short IS NOT NULL AND length(trim(cntt.name_short)) > 0 THEN cntt.name_short else cntt.name END AS containertypename,
1112 f.id as file_id,
1113 f.name as filename,
1114 ( SELECT sum(sc.grossweight) AS sum
1115 FROM cc_shipmentbycontainer sc
1116 WHERE sc.filetrafficcontainer_id = cnt.id) AS grossweight,
1117 ( SELECT sum(sc.volume) AS sum
1118 FROM cc_shipmentbycontainer sc
1119 WHERE sc.filetrafficcontainer_id = cnt.id) AS volume,
1120 cntt.maxweight,
1121 cntt.volume AS maxwvolume,
1122 round(COALESCE(( SELECT sum(sc.grossweight) AS sum
1123 FROM cc_shipmentbycontainer sc
1124 WHERE sc.filetrafficcontainer_id = cnt.id), 0::numeric) * 100::numeric /
1125 CASE
1126 WHEN COALESCE(cntt.maxweight, 1) > 0 THEN COALESCE(cntt.maxweight, 1)
1127 ELSE 1
1128 END::numeric, 0) AS percentweight,
1129 round(COALESCE(( SELECT sum(sc.volume) AS sum
1130 FROM cc_shipmentbycontainer sc
1131 WHERE sc.filetrafficcontainer_id = cnt.id), 0::numeric) * 100::numeric /
1132 CASE
1133 WHEN COALESCE(cntt.volume, 1::numeric) > 0::numeric THEN COALESCE(cntt.volume, 1::numeric)
1134 ELSE 1::numeric
1135 END, 0) AS percentvolume,
1136 CASE
1137 WHEN cntt.classification IS NOT NULL AND cntt.classification::text = 'R'::text THEN 'Y'::text
1138 ELSE 'N'::text
1139 END AS isreefer,
1140 cd.isreinforced,
1141 cd.id AS containerdata_id,
1142 cnt.transportordercontainerheader_id,
1143 cnt.vermassolheader_id,
1144 cd.transportcomment,
1145 cnt.transportservicedate,
1146 cnt.transportfromtime,
1147 cnt.transporttotime,
1148 cnt.transportfromtime2,
1149 cnt.transporttotime2,
1150 cnt.isblanket,
1151 cnt.isflexi,
1152 seal.seal as seal,
1153 seal2.seal as seal2,
1154 seal3.seal as seal3,
1155 seal4.seal as seal4,
1156 seal5.seal as seal5,
1157 cnt.iscontainerplatecalculatedfromcrystalbox,
1158 cnt.issealcalculatedfromcrystalbox,
1159 cnt.admitasenumbermanual,
1160 cnt.entreguesenumbermanual
1161 FROM cc_filetrafficcontainer cnt
1162 LEFT JOIN cc_containertype cntt ON cntt.id = cnt.containertype_id
1163 LEFT JOIN cc_filetrafficcontainerdata cd ON cd.filetrafficcontainer_id = cnt.id
1164 LEFT JOIN cc_filetraffic ftr on ftr.id = cnt.filetraffic_id
1165 LEFT JOIN cc_file f on f.id = ftr.file_id
1166 LEFT JOIN cc_filetrafficcontainerseal seal on seal.filetrafficcontainer_id = cnt.id and seal.issuer = 'CAR'
1167 LEFT JOIN cc_filetrafficcontainerseal seal2 on seal2.filetrafficcontainer_id = cnt.id and seal2.issuer = 'CA2'
1168 LEFT JOIN cc_filetrafficcontainerseal seal3 on seal3.filetrafficcontainer_id = cnt.id and seal3.issuer = 'CA3'
1169 LEFT JOIN cc_filetrafficcontainerseal seal4 on seal4.filetrafficcontainer_id = cnt.id and seal4.issuer = 'CA4'
1170 LEFT JOIN cc_filetrafficcontainerseal seal5 on seal5.filetrafficcontainer_id = cnt.id and seal5.issuer = 'CA5';
1171
1172
1173-- COMMODITIES LIST WITH LOADED VALUES;
1174-- ##############################################################################################
1175CREATE OR REPLACE VIEW cc_shipmentcommview AS
1176 SELECT com.id,
1177 com.shipment_id,
1178 s.name,
1179 com.description,
1180 com.packages,
1181 com.packagetype_id,
1182 com.marks,
1183 com.grossweight,
1184 com.volume,
1185 ( SELECT sum(sc.packages) AS sum
1186 FROM cc_shipmentbycontainer sc
1187 WHERE sc.shipmentcommodity_id = com.id) AS loadpackages,
1188 ( SELECT sum(sc.grossweight) AS sum
1189 FROM cc_shipmentbycontainer sc
1190 WHERE sc.shipmentcommodity_id = com.id) AS loadgrossweight,
1191 ( SELECT sum(sc.volume) AS sum
1192 FROM cc_shipmentbycontainer sc
1193 WHERE sc.shipmentcommodity_id = com.id) AS loadvolume,
1194 ft.id AS filetraffic_id,
1195 pl.language_id AS packagetypelanguage_id,
1196 pl.name AS packagetypename,
1197 sd.imoclass,
1198 s.file_id,
1199 ft.transportmode
1200 FROM cc_shipmentcomm com
1201 LEFT JOIN cc_shipment s ON s.id = com.shipment_id
1202 LEFT JOIN cc_filetraffic ft ON ft.file_id = s.file_id
1203 LEFT JOIN cc_packagetypelang pl ON pl.packagetype_id = com.packagetype_id
1204 LEFT JOIN cc_shipmentcommdangerous sd ON sd.shipmentcommodity_id = com.id AND sd.imoline = 1;
1205
1206-- SHIPMENT COMMODITIES DETAIL BY CONTAINER;
1207-- ##############################################################################################
1208CREATE OR REPLACE VIEW cc_shipmentbycontainerview AS
1209 SELECT sc.id,
1210 s.id AS shipment_id,
1211 com.id AS shipmentcommodity_id,
1212 s.name,
1213 fc.containerid,
1214 fc.containerplate,
1215 com.description,
1216 sc.packages,
1217 sc.grossweight,
1218 sc.volume,
1219 com.packagetype_id,
1220 pk.code AS packagetypecode,
1221 pkl.name AS packagetypename,
1222 pkl.language_id AS packagetypelanguage_id,
1223 ft.id AS filetraffic_id,
1224 sc.filetrafficcontainer_id,
1225 COALESCE(ct.name_short, ct.name) AS containertypename,
1226 com.marks,
1227 com.customstariffheading,
1228 sc.editshippinginstructionsdescription,
1229 sc.shippinginstructionsdescription,
1230 sc.editshippinginstructionsmarks,
1231 sc.shippinginstructionsmarks,
1232 sc.editshippinginstructionscustomstariffheading,
1233 sc.shippinginstructionscustomstariffheading,
1234 sc.blclausestext,
1235 str.shipper_id,
1236 str.consignee_id,
1237 ftr.destination_id,
1238 un.country_id AS portcountrydestinationd_id,
1239 com.purchaseorders,
1240 str.incoterm_id,
1241 s.customerref,
1242 fc.carrierreference,
1243 seal.seal,
1244 seal2.seal as seal2,
1245 fc.isblanket,
1246 fc.isflexi
1247 FROM cc_shipmentbycontainer sc
1248 LEFT JOIN cc_shipmentcomm com ON com.id = sc.shipmentcommodity_id
1249 LEFT JOIN cc_shipment s ON s.id = com.shipment_id
1250 LEFT JOIN cc_shipmenttraffic str ON str.shipment_id = s.id
1251 LEFT JOIN cc_filetrafficcontainer fc ON fc.id = sc.filetrafficcontainer_id
1252 LEFT JOIN cc_filetraffic ftr ON ftr.file_id = s.file_id
1253 LEFT JOIN cc_containertype ct ON ct.id = fc.containertype_id
1254 LEFT JOIN cc_filetrafficcontainerseal seal ON seal.filetrafficcontainer_id = fc.id AND seal.issuer::text = 'CAR'::text
1255 LEFT JOIN cc_filetrafficcontainerseal seal2 ON seal2.filetrafficcontainer_id = fc.id AND seal2.issuer::text = 'CA2'::text
1256 LEFT JOIN cc_packagetype pk ON pk.id = com.packagetype_id
1257 LEFT JOIN cc_packagetypelang pkl ON pkl.packagetype_id = com.packagetype_id
1258 LEFT JOIN cc_filetraffic ft ON ft.file_id = s.file_id
1259 LEFT JOIN cc_unlocode un ON un.id = ftr.destination_id;
1260
1261-- SHIPMENT TRAFFIC MAR;
1262-- ##############################################################################################
1263CREATE OR REPLACE VIEW cc_shipmenttrafficview AS
1264 SELECT f.delegation_id, s.id AS shipment_id,
1265 st.id AS shipmenttraffic_id,
1266 s.file_id,
1267 f.filetype,
1268
1269COALESCE(
1270 CASE
1271 WHEN f.filetype::text = 'GEN'::text THEN fg.servicedate
1272 WHEN f.filetype::text = 'TRA'::text AND ft.trafficflow::text = 'E'::text THEN ft.etd
1273 WHEN f.filetype::text = 'TRA'::text AND ft.trafficflow::text = 'C'::text THEN ft.etd
1274 WHEN f.filetype::text = 'TRA'::text THEN ft.eta
1275 ELSE f.datecreation
1276 END, f.datecreation) AS servicedate,
1277 s.name, s.customer_id,
1278 COALESCE(cpa.name, COALESCE(cp.name_short, cp.name)) AS customername,
1279 s.customerref,
1280 inc.code AS incoterm,
1281 COALESCE(spa.name, COALESCE(sp.name_short, sp.name)) AS shippername,
1282 COALESCE(copa.name, COALESCE(cop.name_short, cop.name)) AS consigneename,
1283 st.subcorrespondent_id,
1284 COALESCE(ssa.name, COALESCE(ss.name_short, ss.name)) AS subcorrespondentname,
1285 sum.containerplate,
1286 sum.containersnumber,
1287 sum.packages,
1288 sum.grossweight,
1289 sum.volume,
1290 sum.isdangerousgoods AS isdangerous,
1291 ft.transportmode, ft.trafficflow, st.blnumber
1292 , st.incoterm_id
1293 , COALESCE(u1.country_id, COALESCE(ai1.country_id, ft.countryorigin_id)) as countryorigin_id
1294 , COALESCE(u2.country_id, COALESCE(ai2.country_id, ft.countrydestination_id)) as countrydestination_id
1295 , st.shipper_id, st.consignee_id, s.salesrepresentative_id, ft.correspondent_id
1296 , crp.agentnetwork_id, crp.agentnetwork2_id, crp.agentnetwork3_id, crp.agentnetwork4_id, crp.agentnetwork5_id, crp.agentnetwork6_id
1297 , COALESCE(ft.origin_id, COALESCE(ft.airportorigin_id, ft.countryorigin_id)) as trafficorigin_id
1298 , COALESCE(ft.destination_id, COALESCE(ft.airportdestination_id, ft.countrydestination_id)) as trafficdestination_id
1299 , st.placereceipt_id, st.placedelivery_id
1300 FROM cc_shipment s
1301 LEFT JOIN cc_partyaddress cpa ON cpa.id = s.customer_id
1302 LEFT JOIN cc_party cp ON cp.id = cpa.party_id
1303 LEFT JOIN cc_shipmenttraffic st ON st.shipment_id = s.id
1304 LEFT JOIN cc_filetraffic ft ON ft.file_id = s.file_id
1305 LEFT JOIN cc_file f on f.id = s.file_id
1306 LEFT JOIN cc_incoterm inc ON inc.id = st.incoterm_id
1307 LEFT JOIN cc_partyaddress spa ON spa.id = st.shipper_id
1308 LEFT JOIN cc_party sp ON sp.id = spa.party_id
1309 LEFT JOIN cc_partyaddress copa ON copa.id = st.consignee_id
1310 LEFT JOIN cc_party cop ON cop.id = copa.party_id
1311 LEFT JOIN cc_shipmentsummary sum ON sum.shipment_id = s.id
1312 LEFT JOIN cc_filegeneral fg on fg.file_id = s.file_id
1313
1314 LEFT JOIN cc_partyaddress ssa ON ssa.id = st.subcorrespondent_id
1315 LEFT JOIN cc_party ss ON ss.id = ssa.party_id
1316
1317 LEFT JOIN cc_unlocode u1 on u1.id = ft.origin_id
1318 LEFT JOIN cc_unlocode u2 on u2.id = ft.destination_id
1319 LEFT JOIN cc_airport ai1 on ai1.id = ft.airportorigin_id
1320 LEFT JOIN cc_airport ai2 on ai2.id = ft.airportdestination_id
1321 LEFT JOIN cc_partyaddress crpa on crpa.id = ft.correspondent_id
1322 LEFT JOIN cc_party crp on crp.id = crpa.party_id;
1323
1324-- FILE TRAFFIC CONTAINER VIEW 2;
1325-- ##############################################################################################
1326CREATE OR REPLACE VIEW cc_filetrafficcontainerview2 AS
1327 SELECT cnt.id,
1328 cnt.filetraffic_id,
1329 cnt.containerid,
1330 ct.name AS containertypename,
1331 cnt.containerplate,
1332 cs.seal,
1333 cs2.seal AS seal2,
1334 cnt.isblanket,
1335 cnt.isflexi,
1336 br.bookingnumber,
1337 br.status AS bookingstatus,
1338 cnt.carrierreference,
1339 cnt.iscontainerplatecalculatedfromcrystalbox,
1340 cnt.issealcalculatedfromcrystalbox,
1341 cnt.admitasenumbermanual,
1342 cnt.entreguesenumbermanual,
1343 ( SELECT DISTINCT s.name
1344 FROM cc_shipmentbycontainer sbc
1345 LEFT JOIN cc_shipmentcomm com ON com.id = sbc.shipmentcommodity_id
1346 LEFT JOIN cc_shipment s ON s.id = com.shipment_id
1347 WHERE sbc.filetrafficcontainer_id = cnt.id
1348 OFFSET 0
1349 LIMIT 1) AS shipment1_id,
1350 ( SELECT DISTINCT s.name
1351 FROM cc_shipmentbycontainer sbc
1352 LEFT JOIN cc_shipmentcomm com ON com.id = sbc.shipmentcommodity_id
1353 LEFT JOIN cc_shipment s ON s.id = com.shipment_id
1354 WHERE sbc.filetrafficcontainer_id = cnt.id
1355 OFFSET 1
1356 LIMIT 1) AS shipment2_id,
1357 ( SELECT DISTINCT s.name
1358 FROM cc_shipmentbycontainer sbc
1359 LEFT JOIN cc_shipmentcomm com ON com.id = sbc.shipmentcommodity_id
1360 LEFT JOIN cc_shipment s ON s.id = com.shipment_id
1361 WHERE sbc.filetrafficcontainer_id = cnt.id
1362 OFFSET 2
1363 LIMIT 1) AS shipment3_id,
1364 ( SELECT DISTINCT s.name
1365 FROM cc_shipmentbycontainer sbc
1366 LEFT JOIN cc_shipmentcomm com ON com.id = sbc.shipmentcommodity_id
1367 LEFT JOIN cc_shipment s ON s.id = com.shipment_id
1368 WHERE sbc.filetrafficcontainer_id = cnt.id
1369 OFFSET 3
1370 LIMIT 1) AS shipment4_id
1371
1372 FROM cc_filetrafficcontainer cnt
1373 LEFT JOIN cc_bookingcontainerheader br ON br.id = cnt.bookingcontainerheader_id
1374 LEFT JOIN cc_containertype ct ON ct.id = cnt.containertype_id
1375 LEFT JOIN cc_filetrafficcontainerseal cs ON cs.filetrafficcontainer_id = cnt.id AND cs.issuer::text = 'CAR'::text
1376 LEFT JOIN cc_filetrafficcontainerseal cs2 ON cs2.filetrafficcontainer_id = cnt.id AND cs2.issuer::text = 'CA2'::text;
1377
1378-- PARTIES: SHIPPING LINES;
1379-- ##############################################################################################
1380CREATE OR REPLACE VIEW cc_partyshippinglineview AS
1381 SELECT p.company_id, p.id,
1382 COALESCE(p.name_short, p.name) AS name
1383 FROM cc_party p
1384 WHERE p.isshippingline = 'Y'::bpchar;
1385
1386-- PARTIES: CONSOLIDATORS;
1387-- ##############################################################################################
1388CREATE OR REPLACE VIEW cc_partyconsolidatorview AS
1389 SELECT p.company_id, p.id,
1390 COALESCE(p.name_short, p.name) AS name
1391 FROM cc_party p
1392 WHERE p.isnvocc = 'Y'::bpchar;
1393
1394-- PARTY ADDRESSES;
1395-- ##############################################################################################
1396CREATE OR REPLACE VIEW cc_partyaddressview AS
1397 SELECT ad.id,
1398 COALESCE(ad.name, (((COALESCE(p.name_short, p.name)::text || ' ('::text) || COALESCE(ad.city, ad.province)::text) || ')'::text)::character varying) AS name,
1399 COALESCE(ad.name, ((COALESCE(p.name_short, p.name)::text)::character varying)) AS nameWithoutCity,
1400 ad.name as partyaddressname,
1401 p.name AS fiscalname,
1402 p.taxid,
1403 ad.province,
1404 ad.street,
1405 ad.zipcode,
1406 cou.id AS country_id,
1407 COALESCE(coul.name, cou.name) AS countryname,
1408 lang.id AS aslanguage_id,
1409 ad.unlocode_id,
1410 ad.city,
1411 ad.party_id,
1412 CASE
1413 WHEN p.fiscaladdress_id IS NOT NULL AND ad.id = p.fiscaladdress_id THEN 'Y'::text
1414 ELSE 'N'::text
1415 END AS isfiscal,
1416 ad.phone,
1417 ad.fax,
1418 ad.email,
1419 ad.contactperson,
1420 ad.isdelegation,
1421 ad.isinvoicing,
1422 ad.iswarehouse,
1423 lang.id AS language_id,
1424 ad.unlocodecity_id,
1425 ad.unlocodeprovince_id
1426 FROM cc_partyaddress ad
1427 LEFT JOIN cc_language lang ON lang.isactive = 'Y'::bpchar
1428 LEFT JOIN cc_party p ON p.id = ad.party_id
1429 LEFT JOIN cc_countrylang coul ON coul.country_id = ad.country_id AND coul.language_id = lang.id
1430 LEFT JOIN cc_country cou ON cou.id = ad.country_id;
1431
1432-- PARTIES;
1433-- ##############################################################################################
1434CREATE OR REPLACE VIEW cc_partyview AS
1435 SELECT p.id,
1436 p.code,
1437 p.fiscaladdress_id,
1438 p.name,
1439 p.name_short,
1440 p.taxid,
1441 COALESCE(pa.city, pa.province) AS city,
1442 lan.id AS language_id,
1443 p.country_id,
1444 COALESCE(coul.name, cou.name) AS countryname,
1445 pa.phone,
1446 pa.email,
1447 p.iscustomer,
1448 p.isvendor,
1449 p.isagent,
1450 p.isfreightforwarder,
1451 p.isshippingline,
1452 p.isshippingagent,
1453 p.isairline,
1454 p.isgsa,
1455 p.istruck,
1456 p.ishandlingagent,
1457 p.isnvocc,
1458 p.iswarehouse,
1459 p.ispcs,
1460 p.isportterminal,
1461 p.isinsurancecompany,
1462 p.iscustomsagent,
1463 p.issalesrepresentative,
1464 p.ispotential,
1465 p.isweighercenter,
1466 p.isagentsnetwork,
1467 car.scaccode,
1468 air.airlinenumericcode,
1469 air.iatacode,
1470 air.icaocode,
1471 CASE WHEN comp.id IS NOT NULL THEN 'Y' ELSE 'N' END as iscompany,
1472 p.company_id,
1473 p.isactive,
1474 p.evaluation,
1475 CASE WHEN p.evaluation IS NULL THEN '' ELSE (select range.icon from cc_form_evaluation_gdp_evaluation_range range where range.percentage >= p.evaluation ORDER BY range.percentage ASC LIMIT 1) END as icon,
1476 CASE WHEN p.evaluation IS NULL THEN '' ELSE (select range.styleclass from cc_form_evaluation_gdp_evaluation_range range where range.percentage >= p.evaluation ORDER BY range.percentage ASC LIMIT 1) END as styleclass,
1477 p.isgdp, p.gsa_id, COALESCE(gsa.name_short, gsa.name) as gsaname
1478 , cus.a3status as customera3status, pro.a3status as providera3status, p.activity_id, acl.name as activityname, p.issubcorrespondent, cus.subcorrespondent_id, COALESCE(scpa.name, COALESCE(scp.name_short, scp.name)) as subcorrespondentname
1479 FROM cc_party p
1480 LEFT JOIN cc_partyaddress pa ON pa.id = p.fiscaladdress_id
1481 LEFT JOIN cc_language lan ON lan.isactive = 'Y'::bpchar
1482 LEFT JOIN cc_countrylang coul ON coul.country_id = p.country_id AND coul.language_id = lan.id
1483 LEFT JOIN cc_country cou ON cou.id = p.country_id
1484 LEFT JOIN cc_carrier car ON car.party_id = p.id
1485 LEFT JOIN cc_airline air ON air.party_id = p.id
1486 LEFT JOIN cc_company comp ON comp.party_id = p.id
1487 LEFT JOIN cc_party gsa on gsa.id = p.gsa_id
1488 LEFT JOIN cc_customer cus on cus.party_id = p.id
1489 LEFT JOIN cc_provider pro on pro.party_id = p.id
1490 LEFT JOIN cc_activitylang acl on acl.language_id = lan.id and acl.activity_id = p.activity_id
1491 LEFT JOIN cc_partyaddress scpa on scpa.id = cus.subcorrespondent_id
1492 LEFT JOIN cc_party scp on scp.id = scpa.party_id;
1493
1494-- AIRLINES;
1495-- ##############################################################################################
1496CREATE OR REPLACE VIEW cc_airlineview AS
1497 SELECT air.id,
1498 COALESCE(p.name_short, p.name) AS name,
1499 COALESCE(coul.name, cou.name) AS countryname,
1500 lang.id AS language_id,
1501 air.airlinenumericcode,
1502 air.iatacode,
1503 air.icaocode,
1504 p.isactive
1505 FROM cc_airline air
1506 LEFT JOIN cc_language lang ON lang.id IS NOT NULL
1507 LEFT JOIN cc_party p ON p.id = air.party_id
1508 LEFT JOIN cc_countrylang coul ON coul.country_id = p.country_id AND coul.language_id = lang.id
1509 LEFT JOIN cc_country cou ON cou.id = p.country_id;
1510-- FILES TRAFFIC: AIR
1511-- ##############################################################################################
1512CREATE OR REPLACE VIEW cc_filetrafficair AS
1513 SELECT f.delegation_id,
1514 f.isactive,
1515 ft.id,
1516 ft.file_id,
1517 ft.transportmode,
1518 ft.trafficflow,
1519 ft.flightnumber,
1520 ft.airportorigin_id,
1521 ft.airportdestination_id,
1522 ft.airline_id,
1523 ft.correspondent_id,
1524 f.name,
1525 ft.awbtype,
1526 ft.etd,
1527 ft.eta,
1528 aor.code AS origincode,
1529 aor.name AS originname,
1530 ades.code AS destinationcode,
1531 ades.name AS destinationname,
1532 f.status,
1533 ft.blnumber,
1534 CASE
1535 WHEN ft.istransferred = 'Y'::bpchar THEN COALESCE(ffpa.name, COALESCE(ffp.name_short, ffp.name))
1536 ELSE COALESCE(alp.name_short, alp.name)
1537 END AS airlinename,
1538 ali.iatacode,
1539 fs.customername,
1540 fs.customerref,
1541 fs.numshipments,
1542 fs.isdangerous,
1543 fs.istemperaturecontrol,
1544 fs2.statusinvpurchase,
1545 fs2.statusinvsale,
1546 fs2.isrisk,
1547 fs2.isincident,
1548 ali.trackandtraceurl,
1549 f.isfile
1550 , f.grmsyncstatus, ft.cargoimpstatus, f.risponsable_id,
1551 f.docrisponsable_id, u1.name as risponsablename
1552, u2.name as docrisponsablename
1553 FROM cc_file f
1554 LEFT JOIN cc_filetraffic ft ON ft.file_id = f.id
1555 LEFT JOIN cc_filetrafficsummary fs ON fs.filetraffic_id = ft.id
1556 LEFT JOIN cc_filesummary fs2 ON fs2.file_id = f.id
1557 LEFT JOIN cc_airport aor ON aor.id = ft.airportorigin_id
1558 LEFT JOIN cc_airport ades ON ades.id = ft.airportdestination_id
1559 LEFT JOIN cc_airline ali ON ali.id = ft.airline_id
1560 LEFT JOIN cc_party alp ON alp.id = ali.party_id
1561 LEFT JOIN cc_partyaddress ffpa ON ffpa.id = ft.freightforwarder_id
1562 LEFT JOIN cc_party ffp ON ffp.id = ffpa.party_id
1563 LEFT JOIN cc_useraccess u1 on u1.id = f.risponsable_id
1564 LEFT JOIN cc_useraccess u2 on u2.id = f.docrisponsable_id
1565 WHERE ft.transportmode::text = 'AIR'::text;
1566
1567-- AIPORTS;
1568-- ##############################################################################################
1569CREATE OR REPLACE VIEW cc_airportview AS
1570 SELECT air.id,
1571 air.name,
1572 air.code,
1573 lang.id AS language_id,
1574 air.country_id,
1575 COALESCE(col.name, cou.name) AS countryname,
1576 air.isactive, air.numberofusages
1577 FROM cc_airport air
1578 LEFT JOIN cc_country cou ON cou.id = air.country_id
1579 LEFT JOIN cc_language lang ON 1 = 1
1580 LEFT JOIN cc_countrylang col ON col.country_id = cou.id AND col.language_id = lang.id;
1581
1582-- COUNTRIES;
1583-- ##############################################################################################
1584CREATE OR REPLACE VIEW cc_countryview AS
1585 SELECT cou.id,
1586 cou.code,
1587 cou.numericcode,
1588 cou.name,
1589 coul.name AS translatedname,
1590 lang.id AS language_id,
1591 coula.name AS countrylanguagename,
1592 cou.iseu,
1593 curl.name AS currencyname,
1594 cou.isactive
1595 FROM cc_country cou
1596 LEFT JOIN cc_language lang ON lang.isactive = 'Y'::bpchar
1597 LEFT JOIN cc_countrylang coul ON coul.country_id = cou.id AND coul.language_id = lang.id
1598 LEFT JOIN cc_language coula ON coula.id = cou.language_id
1599 LEFT JOIN cc_currencylang curl ON curl.parent_id = cou.currency_id AND curl.language_id = lang.id;
1600
1601-- FILE VAL CURRENCIES (FULL);
1602-- ##############################################################################################
1603CREATE OR REPLACE VIEW cc_filevalcurrencyexchangeview AS
1604 SELECT DISTINCT COALESCE(f.id, f2.id) AS file_id,
1605 cf.id AS currencyfrom_id,
1606 cf.code AS currencyfromcode,
1607 cfl.name AS currencyfromname,
1608 cfl.language_id AS currencyfromlanguage_id,
1609 ct.id AS currencyto_id,
1610 ct.code AS currencytocode,
1611 ctl.name AS currencytoname,
1612 ctl.language_id AS currencytolanguage_id,
1613 fve.exchangesale,
1614 fve.exchangecost AS exchangecost
1615 FROM cc_filevalsale fvs
1616 LEFT JOIN cc_file f ON f.id = fvs.file_id
1617 LEFT JOIN cc_shipment shp ON shp.id = fvs.shipment_id
1618 LEFT JOIN cc_file f2 ON f2.id = shp.file_id
1619 LEFT JOIN cc_delegation del ON del.id = COALESCE(f2.delegation_id, f.delegation_id)
1620 LEFT JOIN cc_partyaddress pa ON pa.id = fvs.customer_id
1621 LEFT JOIN cc_party p ON p.id = pa.party_id
1622 LEFT JOIN cc_currency cf ON cf.id = fvs.currency_id
1623 LEFT JOIN cc_currencylang cfl ON cfl.parent_id = cf.id
1624 LEFT JOIN cc_currency ct ON ct.id = del.currency_id
1625 LEFT JOIN cc_currencylang ctl ON ctl.parent_id = ct.id
1626 LEFT JOIN cc_filevalcurrencyexchange fve ON fve.file_id = COALESCE(f2.id, f.id) AND fve.currencyfrom_id = fvs.currency_id AND fve.currencyto_id = del.currency_id
1627 WHERE fvs.currency_id IS NOT NULL AND del.currency_id IS NOT NULL AND fvs.currency_id <> del.currency_id
1628 UNION
1629 SELECT DISTINCT COALESCE(f.id, f2.id) AS file_id,
1630 cf.id AS currencyfrom_id,
1631 cf.code AS currencyfromcode,
1632 cfl.name AS currencyfromname,
1633 cfl.language_id AS currencyfromlanguage_id,
1634 ct.id AS currencyto_id,
1635 ct.code AS currencytocode,
1636 ctl.name AS currencytoname,
1637 ctl.language_id AS currencytolanguage_id,
1638 fve.exchangesale,
1639 fve.exchangecost AS exchangecost
1640 FROM cc_filevalsale fvs
1641 LEFT JOIN cc_file f ON f.id = fvs.file_id
1642 LEFT JOIN cc_shipment shp ON shp.id = fvs.shipment_id
1643 LEFT JOIN cc_file f2 ON f2.id = shp.file_id
1644 LEFT JOIN cc_partyaddress pa ON pa.id = fvs.customer_id
1645 LEFT JOIN cc_party p ON p.id = pa.party_id
1646 LEFT JOIN cc_currency cf ON cf.id = fvs.currency_id
1647 LEFT JOIN cc_currencylang cfl ON cfl.parent_id = cf.id
1648 LEFT JOIN cc_currency ct ON ct.id = p.currency_id
1649 LEFT JOIN cc_currencylang ctl ON ctl.parent_id = ct.id
1650 LEFT JOIN cc_filevalcurrencyexchange fve ON fve.file_id = COALESCE(f2.id, f.id) AND fve.currencyfrom_id = fvs.currency_id AND fve.currencyto_id = p.currency_id
1651 WHERE fvs.currency_id IS NOT NULL AND p.currency_id IS NOT NULL AND fvs.currency_id <> p.currency_id
1652 UNION
1653 SELECT DISTINCT COALESCE(f.id, f2.id) AS file_id,
1654 cf.id AS currencyfrom_id,
1655 cf.code AS currencyfromcode,
1656 cfl.name AS currencyfromname,
1657 cfl.language_id AS currencyfromlanguage_id,
1658 ct.id AS currencyto_id,
1659 ct.code AS currencytocode,
1660 ctl.name AS currencytoname,
1661 ctl.language_id AS currencytolanguage_id,
1662 fve.exchangesale AS exchangesale,
1663 fve.exchangecost
1664 FROM cc_filevalpurchase fvs
1665 LEFT JOIN cc_file f ON f.id = fvs.file_id
1666 LEFT JOIN cc_shipment shp ON shp.id = fvs.shipment_id
1667 LEFT JOIN cc_file f2 ON f2.id = shp.file_id
1668 LEFT JOIN cc_partyaddress pa ON pa.id = fvs.vendor_id
1669 LEFT JOIN cc_party p ON p.id = pa.party_id
1670 LEFT JOIN cc_currency cf ON cf.id = fvs.currency_id
1671 LEFT JOIN cc_currencylang cfl ON cfl.parent_id = cf.id
1672 LEFT JOIN cc_currency ct ON ct.id = p.currency_id
1673 LEFT JOIN cc_currencylang ctl ON ctl.parent_id = ct.id
1674 LEFT JOIN cc_filevalcurrencyexchange fve ON fve.file_id = COALESCE(f2.id, f.id) AND fve.currencyfrom_id = fvs.currency_id AND fve.currencyto_id = p.currency_id
1675 WHERE fvs.currency_id IS NOT NULL AND p.currency_id IS NOT NULL AND fvs.currency_id <> p.currency_id
1676 UNION
1677 SELECT DISTINCT COALESCE(f.id, f2.id) AS file_id,
1678 cf.id AS currencyfrom_id,
1679 cf.code AS currencyfromcode,
1680 cfl.name AS currencyfromname,
1681 cfl.language_id AS currencyfromlanguage_id,
1682 ct.id AS currencyto_id,
1683 ct.code AS currencytocode,
1684 ctl.name AS currencytoname,
1685 ctl.language_id AS currencytolanguage_id,
1686 fve.exchangesale AS exchangesale,
1687 fve.exchangecost
1688 FROM cc_filevalpurchase fvs
1689 LEFT JOIN cc_file f ON f.id = fvs.file_id
1690 LEFT JOIN cc_shipment shp ON shp.id = fvs.shipment_id
1691 LEFT JOIN cc_file f2 ON f2.id = shp.file_id
1692 LEFT JOIN cc_delegation del ON del.id = COALESCE(f2.delegation_id, f.delegation_id)
1693 LEFT JOIN cc_partyaddress pa ON pa.id = fvs.vendor_id
1694 LEFT JOIN cc_party p ON p.id = pa.party_id
1695 LEFT JOIN cc_currency cf ON cf.id = fvs.currency_id
1696 LEFT JOIN cc_currencylang cfl ON cfl.parent_id = cf.id
1697 LEFT JOIN cc_currency ct ON ct.id = del.currency_id
1698 LEFT JOIN cc_currencylang ctl ON ctl.parent_id = ct.id
1699 LEFT JOIN cc_filevalcurrencyexchange fve ON fve.file_id = COALESCE(f2.id, f.id) AND fve.currencyfrom_id = fvs.currency_id AND fve.currencyto_id = del.currency_id
1700 WHERE fvs.currency_id IS NOT NULL AND del.currency_id IS NOT NULL AND fvs.currency_id <> del.currency_id;
1701
1702-- SALE INVOICE HEADER;
1703-- ##############################################################################################
1704CREATE OR REPLACE VIEW cc_saleinvoiceheaderview AS
1705 SELECT inv.delegation_id,
1706 inv.id,
1707 inv.name,
1708 inv.invoicedate,
1709 inv.invoicetype,
1710 COALESCE(inv.file_id, shp.file_id) AS file_id,
1711 inv.shipment_id,
1712 inv.customer_id,
1713 COALESCE(pa.name, COALESCE(p.name_short, p.name)) AS customername,
1714 COALESCE(fil2.name, fil.name) AS filename,
1715 shp.name AS shipmentname,
1716 curl.language_id AS curlanguage_id,
1717 curl.name AS curname,
1718 cur.decimals AS curdecimals,
1719 cur.symbol AS cursymbol,
1720 inv.baseexempt,
1721 inv.basetax,
1722 inv.totalamount,
1723 inv.iscompleted,
1724 rin.name AS referencedinvoicename,
1725 inv.isgrouping,
1726 inv.accountingstatus,
1727 inv.commentsinternal,
1728 ( SELECT due.duedate
1729 FROM cc_saleinvoiceduedate due
1730 WHERE due.parent_id = inv.id
1731 OFFSET 0
1732 LIMIT 1) AS duedate
1733 , COALESCE(ap.status, ap2.status) as accountingprocessstatus
1734 , COALESCE(ap.esoftcontafilename, ap2.esoftcontafilename) as esoftcontafilename
1735 , inv.ispayed, inv.isoutlaysinvoice, inv.iscancelled, cus.ishideinvoices,
1736 inv.invoiceida3,
1737 inv.walletida3
1738 , inv.datesenttoexternalsgd, inv.issenttoexternalsgd
1739 FROM cc_saleinvoiceheader inv
1740 LEFT JOIN cc_partyaddress pa ON pa.id = inv.customer_id
1741 LEFT JOIN cc_party p ON p.id = pa.party_id
1742 LEFT JOIN cc_file fil ON fil.id = inv.file_id
1743 LEFT JOIN cc_shipment shp ON shp.id = inv.shipment_id
1744 LEFT JOIN cc_file fil2 ON fil2.id = shp.file_id
1745 LEFT JOIN cc_currency cur ON cur.id = inv.currency_id
1746 LEFT JOIN cc_currencylang curl ON curl.parent_id = cur.id
1747 LEFT JOIN cc_saleinvoiceheader rin ON rin.id = inv.referencedinvoice_id
1748 LEFT JOIN cc_accountingentry ae ON ae.id = inv.accountingentry_id
1749 LEFT JOIN cc_accountingprocess ap on ap.id = ae.accountingprocessheader_id
1750 LEFT JOIN cc_accountingprocess ap2 on ap2.id = inv.accountingprocess_id
1751 LEFT JOIN cc_customer cus on cus.party_id = pa.party_id;
1752
1753
1754
1755-- PENDING VALORATIONS BY SHIPMENT;
1756-- ##############################################################################################
1757CREATE OR REPLACE VIEW cc_filevalsaleshipmentview AS
1758 SELECT DISTINCT f.delegation_id,
1759 s.shipment_id,
1760 shp.file_id,
1761 f.datecreation,
1762 shp.customer_id,
1763 st.shipper_id,
1764 st.consignee_id
1765 FROM cc_filevalsale s
1766 RIGHT JOIN cc_shipment shp ON shp.id = s.shipment_id
1767 LEFT JOIN cc_shipmenttraffic st ON st.shipment_id = shp.id
1768 LEFT JOIN cc_file f ON f.id = shp.file_id;
1769
1770-- PENDING VALORATIONS BY SHIPMENT;
1771-- ##############################################################################################
1772CREATE OR REPLACE VIEW cc_filevalsalependingshipmentview AS
1773 SELECT f.delegation_id,
1774 s.shipment_id,
1775 shp.name,
1776 shp.customerref,
1777 shp.file_id,
1778 COALESCE(pa.name, COALESCE(p.name_short, p.name)) AS customername,
1779 f.datecreation,
1780 shp.customer_id,
1781 st.shipper_id,
1782 st.consignee_id,
1783 ft.trafficflow,
1784 ft.transportmode,
1785 sum(round(COALESCE(s.units, 1::numeric) * COALESCE(s.price, 0::numeric) * COALESCE(exc.exchangesale, COALESCE(cex.exchange, COALESCE(( SELECT cex_1.exchange
1786 FROM cc_currencyexchange cex_1
1787 WHERE cex_1.currencyfrom_id = s.currency_id AND cex_1.currencyto_id = del.currency_id AND cex_1.exchangedate::date = f.datecreation::date
1788 ORDER BY cex_1.exchangedate DESC
1789 LIMIT 1), 1::numeric))), COALESCE(curd.decimals, 2))) AS amountfinal
1790 FROM cc_filevalsale s
1791 LEFT JOIN cc_shipment shp ON shp.id = s.shipment_id
1792 LEFT JOIN cc_shipmenttraffic st ON st.shipment_id = shp.id
1793 LEFT JOIN cc_filetraffic ft ON ft.file_id = shp.file_id
1794 LEFT JOIN cc_file f ON f.id = shp.file_id
1795 LEFT JOIN cc_partyaddress pa ON pa.id = shp.customer_id
1796 LEFT JOIN cc_party p ON p.id = pa.party_id
1797 LEFT JOIN cc_currency cur ON cur.id = s.currency_id
1798 LEFT JOIN cc_delegation del ON del.id = f.delegation_id
1799 LEFT JOIN cc_currency curd ON curd.id = del.currency_id
1800 LEFT JOIN cc_filevalcurrencyexchange exc ON exc.file_id = COALESCE(s.file_id, shp.file_id) AND exc.currencyfrom_id = s.currency_id AND exc.currencyto_id = del.currency_id
1801 LEFT JOIN cc_currencyexchange cex ON cex.currencyfrom_id = s.currency_id AND cex.currencyto_id = del.currency_id AND cex.exchangedate::date = f.datecreation::date
1802 WHERE s.isinvoice = 'N'::bpchar
1803 GROUP BY f.delegation_id, s.shipment_id, shp.name, shp.customerref, shp.file_id, COALESCE(pa.name, COALESCE(p.name_short, p.name)), f.datecreation, shp.customer_id, st.shipper_id, st.consignee_id, ft.trafficflow, ft.transportmode
1804 ORDER BY f.delegation_id, s.shipment_id, shp.name, shp.customerref, shp.file_id, COALESCE(pa.name, COALESCE(p.name_short, p.name)), f.datecreation, shp.customer_id, st.shipper_id, st.consignee_id, ft.trafficflow, ft.transportmode;
1805
1806-- INVOICE CONCEPTS VIEW;
1807-- ##############################################################################################
1808CREATE OR REPLACE VIEW cc_invoiceconceptview AS
1809 SELECT ic.delegation_id,
1810 ic.id,
1811 icl.language_id,
1812 icl.name,
1813 ic.invoiceconceptgroup_id,
1814 icg.name AS invoiceconceptgroupname,
1815 ic.invoiceconcepttype_id,
1816 ict.name AS invoiceconcepttypename,
1817 it.classification,
1818 ic.flow,
1819 ic.transportmode,
1820 ic.scopesale,
1821 ic.scopepurchase,
1822 ic.printorder,
1823 ic.isfavourite,
1824 ic.isactive,
1825 ic.isfreightsurchargeimportmanage,
1826 ic.isfreightsurchargeexportmanage,
1827 ic.freightsurchargeimportorder,
1828 ic.freightsurchargeexportorder,
1829
1830 COALESCE(ic.iatacharge, ''::character varying)::text || COALESCE(ic.iatachargeto, ''::character varying)::text AS iatacharge,
1831 it.isoutlayvat, it.applyfilegeneral, it.applyfiletraffic, it.applyfilecustoms, it.applyfilewarehousing,
1832 ic.tariffcalculationmode
1833 FROM cc_invoiceconcept ic
1834 LEFT JOIN cc_invoiceconceptlang icl ON icl.parent_id = ic.id
1835 LEFT JOIN cc_invoiceconceptgrouplang icg ON icg.parent_id = ic.invoiceconceptgroup_id AND icg.language_id = icl.language_id
1836 LEFT JOIN cc_invoiceconcepttype it on it.id = ic.invoiceconcepttype_id
1837 LEFT JOIN cc_invoiceconcepttypelang ict ON ict.parent_id = ic.invoiceconcepttype_id AND ict.language_id = icl.language_id;
1838
1839-- SHIPMENTS;
1840-- ##############################################################################################
1841CREATE OR REPLACE VIEW cc_shipmentview AS
1842 SELECT shp.id,
1843 shp.createddate,
1844 shp.createdby_id,
1845 f.delegation_id,
1846 f.filetype,
1847 f.id AS file_id,
1848 f.name AS filename,
1849 ftr.transportmode,
1850 ftr.trafficflow, COALESCE(
1851 CASE
1852 WHEN f.filetype::text = 'GEN'::text THEN fg.servicedate
1853 WHEN f.filetype::text = 'TRA'::text AND ftr.trafficflow::text = 'E'::text THEN ftr.etd
1854 WHEN f.filetype::text = 'TRA'::text AND ftr.trafficflow::text = 'C'::text THEN ftr.etd
1855 WHEN f.filetype::text = 'TRA'::text THEN ftr.eta
1856 ELSE f.datecreation
1857 END, f.datecreation) AS fileservicedate,
1858 f.datecreation AS filedate,
1859 shp.name,
1860 shp.customer_id,
1861 shp.customerref,
1862 shp.salesrepresentative_id,
1863 shp.finalclient_id,
1864 COALESCE(ca.name, COALESCE(cp.name_short, cp.name)) AS customername,
1865 f.datecreation,
1866 ftr.etd,
1867 ftr.eta,
1868 ftr.origin_id,
1869 ftr.destination_id,
1870 lang.id AS language_id,
1871 COALESCE(aor.name, COALESCE(unol.name, uno.name)) AS originaname,
1872 COALESCE(ade.name, COALESCE(undl.name, und.name)) AS destinationname,
1873 aor.id AS airportorigin_id,
1874 aor.name AS airportoriginname,
1875 ade.id AS airportdestination_id,
1876 ade.name AS airportdestinationname,
1877 CASE
1878 WHEN (( SELECT count(DISTINCT sc.filetrafficcontainer_id) AS count
1879 FROM cc_shipmentbycontainer sc
1880 LEFT JOIN cc_shipmentcomm com ON com.id = sc.shipmentcommodity_id
1881 WHERE com.shipment_id = shp.id)) = 1 THEN ( SELECT DISTINCT fcn.containerplate
1882 FROM cc_shipmentbycontainer sc
1883 LEFT JOIN cc_shipmentcomm com ON com.id = sc.shipmentcommodity_id
1884 LEFT JOIN cc_filetrafficcontainer fcn ON fcn.id = sc.filetrafficcontainer_id
1885 WHERE com.shipment_id = shp.id)
1886 ELSE '+'::character varying
1887 END AS containerplate,
1888 ( SELECT sum(COALESCE(com.packages, 0::numeric)) AS sum
1889 FROM cc_shipmentcomm com
1890 WHERE com.shipment_id = shp.id) AS packages,
1891 ( SELECT sum(COALESCE(com.grossweight, 0::numeric)) AS sum
1892 FROM cc_shipmentcomm com
1893 WHERE com.shipment_id = shp.id) AS grossweight,
1894 COALESCE(ali.name_short, COALESCE(ali.name, COALESCE(sl.name_short, sl.name))) AS shippingline,
1895 shpt.shipper_id,
1896 shpt.consignee_id,
1897 ftr.shippingline_id,
1898 ftr.correspondent_id,
1899 ftr.consolidator_id,
1900 f.status
1901 , unpr.id as placereceipt_id
1902 , unprl.name as placereceiptname
1903 , unpd.id as placedelivery_id
1904 , unpdl.name as placedeliveryname, ftr.provisionaldate
1905 FROM cc_shipment shp
1906 LEFT JOIN cc_shipmenttraffic shpt ON shpt.shipment_id = shp.id
1907 LEFT JOIN cc_language lang ON lang.isactive = 'Y'::bpchar
1908 LEFT JOIN cc_filetraffic ftr ON ftr.file_id = shp.file_id
1909 LEFT JOIN cc_file f ON f.id = shp.file_id
1910 LEFT JOIN cc_filegeneral fg ON fg.file_id = f.id
1911 LEFT JOIN cc_party sl ON sl.id = ftr.shippingline_id
1912 LEFT JOIN cc_partyaddress ca ON ca.id = shp.customer_id
1913 LEFT JOIN cc_party cp ON cp.id = ca.party_id
1914 LEFT JOIN cc_unlocode uno ON uno.id = ftr.origin_id
1915 LEFT JOIN cc_unlocodelang unol ON unol.unlocode_id = uno.id AND unol.language_id = lang.id
1916 LEFT JOIN cc_unlocode und ON und.id = ftr.destination_id
1917 LEFT JOIN cc_unlocodelang undl ON undl.unlocode_id = und.id AND undl.language_id = lang.id
1918 LEFT JOIN cc_unlocode unpr ON unpr.id = shpt.placereceipt_id
1919 LEFT JOIN cc_unlocodelang unprl ON unprl.unlocode_id = unpr.id AND unprl.language_id = lang.id
1920 LEFT JOIN cc_unlocode unpd ON unpd.id = shpt.placedelivery_id
1921 LEFT JOIN cc_unlocodelang unpdl ON unpdl.unlocode_id = unpd.id AND unpdl.language_id = lang.id
1922 LEFT JOIN cc_airport aor ON aor.id = ftr.airportorigin_id
1923 LEFT JOIN cc_airport ade ON ade.id = ftr.airportdestination_id
1924 LEFT JOIN cc_airline airl ON airl.id = ftr.airline_id
1925 LEFT JOIN cc_party ali ON ali.id = airl.party_id;
1926
1927-- PARTY TYPES;
1928-- ##############################################################################################
1929CREATE OR REPLACE VIEW cc_partytypeview AS
1930 SELECT ad.id, p.company_id
1931 , COALESCE(ad.name, (((COALESCE(p.name_short, p.name)::text || ' ('::text) || COALESCE(ad.city, COALESCE(ad.province, ''))::text) || ')'::text)::character varying) AS name,
1932 ad.name AS addressname,
1933 p.name AS partyaddress,
1934 p.code,
1935 p.name_short,
1936 p.isagent,
1937 p.isfinalclient,
1938 p.isairline,
1939 p.iscustomer,
1940 p.ispotential,
1941 p.iscustomsagent,
1942 p.isfreightforwarder,
1943 p.ishandlingagent,
1944 p.isinsurancecompany,
1945 p.isnvocc,
1946 p.ispcs,
1947 p.isportterminal,
1948 p.issalesrepresentative,
1949 p.isshippingagent,
1950 p.isshippingline,
1951 p.istruck,
1952 p.isvendor,
1953 p.iswarehouse,
1954 p.isweighercenter,
1955 CASE
1956 WHEN ad.isactive = 'Y'::bpchar AND p.isactive = 'Y'::bpchar THEN 'Y'::text
1957 ELSE 'N'::text
1958 END AS isactive,
1959 ad.user_id,
1960 CASE
1961 WHEN p.fiscaladdress_id = ad.id THEN 'Y'::text
1962 ELSE 'N'::text
1963 END AS isfiscal,
1964 ad.iswarehouse AS isaddresswarehouse,
1965 ad.street,
1966 ad.city,
1967 ad.province,
1968 ad.zipcode,
1969 p.taxid, p.issubcorrespondent
1970 FROM cc_partyaddress ad
1971 LEFT JOIN cc_party p ON p.id = ad.party_id;
1972
1973-- SALE INVOICE HEADER PRINT;
1974-- ##############################################################################################
1975CREATE OR REPLACE VIEW cc_saleinvoiceheaderprint AS
1976 SELECT h.id,
1977 h.customer_id,
1978 COALESCE(pa.name, COALESCE(p.name_short, p.name)) AS customername,
1979 h.name AS invoicename,
1980 h.invoicedate,
1981 ( SELECT string_agg(c_1.email::text, ';'::text) AS string_agg
1982 FROM cc_contact c_1
1983 WHERE c_1.email IS NOT NULL AND c_1.partyaddress_id = h.customer_id) AS email,
1984 COALESCE(h.transportmode, COALESCE(ftr2.transportmode, ftr.transportmode)) AS transportmode,
1985 COALESCE(h.trafficflow, COALESCE(ftr2.trafficflow, ftr.trafficflow)) AS trafficflow
1986 FROM cc_saleinvoiceheader h
1987 LEFT JOIN cc_partyaddress pa ON pa.id = h.customer_id
1988 LEFT JOIN cc_party p ON p.id = pa.party_id
1989 LEFT JOIN cc_customer c ON c.id = h.customer_id
1990 LEFT JOIN cc_delegation del ON del.id = h.delegation_id
1991 LEFT JOIN cc_filetraffic ftr ON ftr.file_id = h.file_id
1992 LEFT JOIN cc_shipment shp ON shp.id = h.shipment_id
1993 LEFT JOIN cc_filetraffic ftr2 ON ftr2.file_id = shp.file_id;
1994
1995-- SALE INVOICE DETAIL;
1996-- ##############################################################################################
1997CREATE OR REPLACE VIEW cc_saleinvoicedetailview AS
1998 SELECT d.id,
1999 d.parent_id AS saleinvoiceheader_id,
2000 d.printorder,
2001 d.printtext,
2002 d.units,
2003 d.price,
2004 d.lineamount,
2005 d.invoicetax_id,
2006 CASE
2007 WHEN d.printtext IS NOT NULL AND length(btrim(d.printtext::text)) > 0 THEN d.printtext
2008 ELSE icl.name
2009 END AS name,
2010 d.filevalsale_id,
2011 v.invoiceconcept_id,
2012 d.currency_id,
2013 cur.code AS currencycode,
2014 cur.decimals AS curdecimals,
2015 COALESCE(cur.symbol, cur.code) AS currencysymbol,
2016 lan.id AS language_id,
2017 itl.name AS invoicetaxname,
2018 h.currency_id AS headercurrency_id,
2019 COALESCE(d.exchange, exc.exchange) AS exchange,
2020 hcur.decimals AS curheaderdecimals,
2021 ict.isoutlayvat,
2022 COALESCE(s.name, f.name) AS filename,
2023 ft.blnumber AS masterbl,
2024 d.shipment_id,
2025 d.file_id,
2026 v.customer_id,
2027 CASE
2028 WHEN f.filetype::text = 'GEN'::text THEN fg.servicedate
2029 WHEN f.filetype::text = 'TRA'::text AND ft.trafficflow::text = 'I'::text THEN ft.eta
2030 WHEN f.filetype::text = 'TRA'::text THEN ft.etd
2031 ELSE f.datecreation
2032 END AS servicedate,
2033 CASE
2034 WHEN f.filetype::text = 'GEN'::text THEN fg.transportmode
2035 WHEN f.filetype::text = 'TRA'::text THEN ft.transportmode
2036 ELSE NULL::character varying
2037 END AS transportmode,
2038 CASE
2039 WHEN f.filetype::text = 'GEN'::text THEN fg.trafficflow
2040 WHEN f.filetype::text = 'TRA'::text THEN ft.trafficflow
2041 ELSE NULL::character varying
2042 END AS trafficflow
2043 FROM cc_saleinvoicedetail d
2044 LEFT JOIN cc_saleinvoiceheader h ON h.id = d.parent_id
2045 LEFT JOIN cc_filevalsale v ON v.id = d.filevalsale_id
2046 LEFT JOIN cc_currency cur ON cur.id = d.currency_id
2047 LEFT JOIN cc_language lan ON lan.id > 0
2048 LEFT JOIN cc_invoicetaxlang itl ON itl.parent_id = d.invoicetax_id AND itl.language_id = lan.id
2049 LEFT JOIN cc_invoiceconceptlang icl ON icl.parent_id = v.invoiceconcept_id AND icl.language_id = lan.id
2050 LEFT JOIN cc_invoiceconcept ic ON ic.id = v.invoiceconcept_id
2051 LEFT JOIN cc_invoiceconcepttype ict ON ict.id = ic.invoiceconcepttype_id
2052 LEFT JOIN cc_saleinvoicecurrencyexchange exc ON exc.saleinvoiceheader_id = d.parent_id AND exc.currencyfrom_id = d.currency_id
2053 LEFT JOIN cc_currency hcur ON hcur.id = h.currency_id
2054 LEFT JOIN cc_shipment s ON s.id = COALESCE(d.shipment_id, v.shipment_id)
2055 LEFT JOIN cc_file f ON f.id = COALESCE(COALESCE(d.file_id, v.file_id), s.file_id)
2056 LEFT JOIN cc_filetraffic ft ON ft.file_id = COALESCE(s.file_id, f.id)
2057 LEFT JOIN cc_filegeneral fg ON fg.file_id = COALESCE(s.file_id, f.id);
2058
2059
2060-- File document view;
2061-- ##############################################################################################
2062CREATE OR REPLACE VIEW cc_filedocumentview AS
2063 SELECT fd.file_id,
2064 NULL::integer AS shipment_id,
2065 fd.id AS filedocument_id,
2066 NULL::integer AS shipmentdocument_id,
2067 NULL::integer AS saleinvoiceheader_id,
2068 NULL::integer AS purchaseinvoiceheader_id,
2069 fd.documenttype,
2070 f.name AS filename,
2071 NULL::character varying AS shipmentname,
2072 fd.createddate,
2073 u1.code AS createdby,
2074 fd.printeddate,
2075 u2.code AS printedby,
2076 CASE
2077 WHEN fd.documenttype::text = 'MAWB'::text OR fd.documenttype::text = 'DAWB'::text THEN ( SELECT awb.id
2078 FROM cc_awbheader awb
2079 WHERE awb.filedocument_id = fd.id)
2080 WHEN fd.documenttype::text = 'ORIGLET_FILE'::text THEN ( SELECT o.id FROM cc_originalsdocumentheader o WHERE o.filedocument_id = fd.id)
2081 WHEN fd.documenttype::text = 'BOOKCONF_FILE'::text THEN fd.file_id
2082 WHEN fd.documenttype::text = 'DOSSIER'::text THEN fd.file_id
2083 WHEN fd.documenttype::text = 'INCIDENT'::text THEN ( SELECT i.id
2084 FROM cc_incident i
2085 WHERE i.filedocument_id = fd.id)
2086 ELSE fd.id
2087 END AS record_id,
2088 fd.absolutefilepath,
2089 fd.messageedi_id,
2090 me.datesent,
2091 me.datereceived,
2092 CASE
2093 WHEN fd.documenttype::text = 'BOOKINGCONTAINER'::text THEN ( SELECT b.status
2094 FROM cc_bookingcontainerheader b
2095 WHERE fd.id = b.filedocument_id)
2096 WHEN fd.documenttype::text = 'APERAK'::text THEN ( SELECT a.status
2097 FROM cc_aperakheader a
2098 WHERE a.filedocument_id = fd.id)
2099 WHEN fd.documenttype::text = 'SHIPPINGINSTRUCTIONS'::text THEN ( SELECT s.status
2100 FROM cc_shippinginstructionsheader s
2101 WHERE s.filedocument_id = fd.id)
2102 WHEN fd.documenttype::text = 'BOOKINGCONTAINERCONFIRMATION'::text THEN ( SELECT bc.status
2103 FROM cc_bookingcontainerheader bc
2104 WHERE bc.filedocument_id = fd.id)
2105 WHEN fd.documenttype::text = 'INCIDENT'::text THEN ( SELECT i.status
2106 FROM cc_incident i
2107 WHERE i.filedocument_id = fd.id)
2108 WHEN fd.documenttype::text = 'TRANSPORTORDERCONTAINER'::text THEN ( SELECT toc.status
2109 FROM cc_transportcontainerheader toc
2110 WHERE toc.filedocument_id = fd.id)
2111 ELSE NULL::character varying
2112 END AS status,
2113 CASE
2114 WHEN fd.documenttype::text = 'TRANSPORTORDERCONTAINER'::text THEN ( SELECT to_char(toc.id, '999999999'::text) AS to_char
2115 FROM cc_transportcontainerheader toc
2116 WHERE toc.filedocument_id = fd.id)
2117 WHEN fd.documenttype::text = 'VERMASSOL'::text THEN (select to_char(vsol.id, '999999999'::text) AS to_char
2118 FROM cc_vermassolheader vsol
2119 WHERE vsol.filedocument_id = fd.id)
2120 ELSE NULL::text
2121 END AS documentname
2122 , fd.datesenttoexternalsgd, fd.issenttoexternalsgd
2123 FROM cc_filedocument fd
2124 LEFT JOIN cc_file f ON fd.file_id = f.id
2125 LEFT JOIN cc_useraccess u1 ON u1.id = fd.createdby_id
2126 LEFT JOIN cc_useraccess u2 ON u2.id = fd.printedby_id
2127 LEFT JOIN cc_messageedi me ON me.id = fd.messageedi_id
2128 UNION
2129 SELECT s.file_id,
2130 sd.shipment_id,
2131 NULL::integer AS filedocument_id,
2132 sd.id AS shipmentdocument_id,
2133 NULL::integer AS saleinvoiceheader_id,
2134 NULL::integer AS purchaseinvoiceheader_id,
2135 sd.documenttype,
2136 f.name AS filename,
2137 s.name AS shipmentname,
2138 sd.createddate,
2139 u1.code AS createdby,
2140 sd.printeddate,
2141 u2.code AS printedby,
2142 CASE
2143 WHEN sd.documenttype::text = 'HAWB'::text THEN ( SELECT awb.id
2144 FROM cc_awbheader awb
2145 WHERE awb.shipmentdocument_id = sd.id)
2146 WHEN sd.documenttype::text = 'ORIGLET_SHIPMENT'::text THEN ( SELECT o.id FROM cc_originalsdocumentheader o WHERE o.shipmentdocument_id = sd.id)
2147 WHEN sd.documenttype::text = 'DOSSIER'::text THEN sd.shipment_id
2148 ELSE sd.id
2149 END AS record_id,
2150 sd.absolutefilepath,
2151 sd.messageedi_id,
2152 me.datesent,
2153 me.datereceived,
2154 CASE
2155 WHEN sd.documenttype::text = 'CUSTOMSORDER'::text THEN ( SELECT
2156 CASE
2157 WHEN co.customsstatus::text = 'COMPLETED'::text THEN ('CHANNEL_'::text || co.customsresult::text)::character varying
2158 ELSE co.customsstatus
2159 END AS customsstatus
2160 FROM cc_customsorderheader co
2161 WHERE sd.id = co.shipmentdocument_id)
2162 WHEN hbl.isoriginalprinted IS NOT NULL and hbl.isoriginalprinted = 'Y' THEN 'HOUSEBLPRINTED'
2163 ELSE NULL::character varying
2164 END AS status,
2165 NULL::text AS documentname
2166 , sd.datesenttoexternalsgd, sd.issenttoexternalsgd
2167 FROM cc_shipmentdocument sd
2168 LEFT JOIN cc_shipment s ON s.id = sd.shipment_id
2169 LEFT JOIN cc_file f ON f.id = s.file_id
2170 LEFT JOIN cc_useraccess u1 ON u1.id = sd.createdby_id
2171 LEFT JOIN cc_useraccess u2 ON u2.id = sd.printedby_id
2172 LEFT JOIN cc_messageedi me ON me.id = sd.messageedi_id
2173 LEFT JOIN cc_houseblheader hbl on hbl.shipmentdocument_id = sd.id
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193 UNION
2194 SELECT COALESCE(si.file_id, s.file_id) AS file_id,
2195 si.shipment_id,
2196 NULL::integer AS filedocument_id,
2197 NULL::integer AS shipmentdocument_id,
2198 si.id AS saleinvoiceheader_id,
2199 NULL::integer AS purchaseinvoiceheader_id,
2200 'SALEINVOICE'::character varying AS documenttype,
2201 f.name AS filename,
2202 s.name AS shipmentname,
2203 si.createddate,
2204 u1.code AS createdby,
2205 si.printeddate,
2206 u2.code AS printedby,
2207 si.id AS record_id,
2208 si.absolutefilepath,
2209 NULL::integer AS messageedi_id,
2210 NULL::timestamp without time zone AS datesent,
2211 NULL::timestamp without time zone AS datereceived,
2212 NULL::character varying AS status,
2213 si.name AS documentname
2214 , si.datesenttoexternalsgd, si.issenttoexternalsgd
2215 FROM cc_saleinvoiceheader si
2216 LEFT JOIN cc_shipment s ON s.id = si.shipment_id
2217 LEFT JOIN cc_file f ON f.id = COALESCE(si.file_id, s.file_id)
2218 LEFT JOIN cc_useraccess u1 ON u1.id = si.createdby_id
2219 LEFT JOIN cc_useraccess u2 ON u2.id = si.printedby_id
2220 UNION
2221 SELECT COALESCE(pid.file_id, s.file_id) AS file_id,
2222 pid.shipment_id,
2223 NULL::integer AS filedocument_id,
2224 NULL::integer AS shipmentdocument_id,
2225 NULL::integer AS saleinvoiceheader_id,
2226 pi.id AS purchaseinvoiceheader_id,
2227 'PURCHASEINVOICE'::character varying AS documenttype,
2228 f.name AS filename,
2229 s.name AS shipmentname,
2230 pi.createddate,
2231 u1.code AS createdby,
2232 NULL::timestamp without time zone AS printeddate,
2233 NULL::character varying AS printedby,
2234 pi.id AS record_id,
2235 at.filepath AS absolutefilepath,
2236 NULL::integer AS messageedi_id,
2237 NULL::timestamp without time zone AS datesent,
2238 NULL::timestamp without time zone AS datereceived,
2239 NULL::character varying AS status,
2240 pi.name AS documentname
2241 , pi.datesenttoexternalsgd, pi.issenttoexternalsgd
2242 FROM cc_purchaseinvoicedetail pid
2243 LEFT JOIN cc_purchaseinvoiceheader pi ON pi.id = pid.parent_id
2244 LEFT JOIN cc_shipment s ON s.id = pid.shipment_id
2245 LEFT JOIN cc_file f ON f.id = COALESCE(pid.file_id, s.file_id)
2246 LEFT JOIN cc_useraccess u1 ON u1.id = pid.createdby_id
2247 LEFT JOIN cc_attachment at ON at.id = pi.attachment_id
2248 GROUP BY COALESCE(pid.file_id, s.file_id), pid.shipment_id, f.name, s.name, pi.createddate, u1.code, pi.id, at.filepath
2249 UNION
2250 SELECT COALESCE(sid.file_id, s.file_id) AS file_id,
2251 sid.shipment_id,
2252 NULL::integer AS filedocument_id,
2253 NULL::integer AS shipmentdocument_id,
2254 si.id AS saleinvoiceheader_id,
2255 NULL::integer AS purchaseinvoiceheader_id,
2256 'SALEINVOICE'::character varying AS documenttype,
2257 f.name AS filename,
2258 s.name AS shipmentname,
2259 si.createddate,
2260 u1.code AS createdby,
2261 si.printeddate,
2262 u2.code AS printedby,
2263 si.id AS record_id,
2264 si.absolutefilepath,
2265 NULL::integer AS messageedi_id,
2266 NULL::timestamp without time zone AS datesent,
2267 NULL::timestamp without time zone AS datereceived,
2268 NULL::character varying AS status,
2269 si.name AS documentname
2270 , si.datesenttoexternalsgd, si.issenttoexternalsgd
2271 FROM cc_saleinvoicedetail sid
2272 LEFT JOIN cc_saleinvoiceheader si ON sid.parent_id = si.id
2273 LEFT JOIN cc_shipment s ON s.id = sid.shipment_id
2274 LEFT JOIN cc_file f ON f.id = COALESCE(sid.file_id, s.file_id)
2275 LEFT JOIN cc_useraccess u1 ON u1.id = si.createdby_id
2276 LEFT JOIN cc_useraccess u2 ON u2.id = si.printedby_id
2277 GROUP BY COALESCE(sid.file_id, s.file_id), sid.shipment_id, si.id, f.name, s.name, si.createddate, u1.code, si.printeddate, u2.code, si.absolutefilepath
2278 UNION
2279 SELECT s.file_id as file_id,
2280 str.shipment_id,
2281 NULL::integer AS filedocument_id,
2282 NULL::integer AS shipmentdocument_id,
2283 NULL::integer AS saleinvoiceheader_id,
2284 NULL::integer AS purchaseinvoiceheader_id,
2285 'COMMERCIALOFFER'::character varying AS documenttype,
2286 null AS filename,
2287 s.name AS shipmentname,
2288 h.createddate,
2289 u1.code AS createdby,
2290 NULL::timestamp without time zone AS printeddate,
2291 NULL::character varying AS printedby,
2292 h.id AS record_id,
2293 NULL::character varying AS absolutefilepath,
2294 NULL::integer AS messageedi_id,
2295 NULL::timestamp without time zone AS datesent,
2296 NULL::timestamp without time zone AS datereceived,
2297 NULL::character varying AS status,
2298 NULL::character varying AS documentname
2299 , s.commercialofferdatesenttoexternalsgd, s.iscommercialoffersenttoexternalsgd
2300 FROM cc_commercialofferservice ser
2301 LEFT JOIN cc_commercialofferheader h on h.id = ser.commercialofferheader_id
2302 LEFT JOIN cc_shipmenttraffic str on str.commercialofferservice_id = ser.id
2303 LEFT JOIN cc_shipment s ON s.id = str.shipment_id
2304 LEFT JOIN cc_useraccess u1 ON u1.id = h.createdby_id WHERE s.id IS NOT NULL;
2305
2306
2307-- File attachment view;
2308-- ##############################################################################################
2309CREATE OR REPLACE VIEW cc_fileattachmentview AS
2310 SELECT fa.id,
2311 fa.file_id,
2312 NULL::integer AS shipment_id,
2313 f.name AS filename,
2314 lang.id AS language_id,
2315 fa.documenttype_id,
2316 COALESCE(dtl.name, fa.documenttypename) AS documenttypename,
2317 fa.documentname,
2318 fa.documentdate,
2319 us.code AS createdby,
2320 us.createddate,
2321 fa.internalfilename,
2322 fa.comments,
2323 fa.absolutefilepath,
2324 fa.fileattachmentparent_id AS attachmentparent_id,
2325 fa.isgroup
2326 , fa.datesenttoexternalsgd, fa.issenttoexternalsgd
2327 FROM cc_fileattachment fa
2328 LEFT JOIN cc_file f ON f.id = fa.file_id
2329 LEFT JOIN cc_language lang ON lang.id > 0
2330 LEFT JOIN cc_documenttypelang dtl ON dtl.documenttype_id = fa.documenttype_id AND dtl.language_id = lang.id
2331 LEFT JOIN cc_useraccess us ON us.id = fa.createdby_id
2332 UNION
2333 SELECT sa.id,
2334 s.file_id,
2335 sa.shipment_id,
2336 s.name AS filename,
2337 lang.id AS language_id,
2338 sa.documenttype_id,
2339 COALESCE(dtl.name, sa.documenttypename) AS documenttypename,
2340 sa.documentname,
2341 sa.documentdate,
2342 us.code AS createdby,
2343 us.createddate,
2344 sa.internalfilename,
2345 sa.comments,
2346 sa.absolutefilepath,
2347 sa.shipmentattachmentparent_id AS attachmentparent_id,
2348 sa.isgroup
2349 , sa.datesenttoexternalsgd, sa.issenttoexternalsgd
2350 FROM cc_shipmentattachment sa
2351 LEFT JOIN cc_shipment s ON s.id = sa.shipment_id
2352 LEFT JOIN cc_language lang ON lang.id > 0
2353 LEFT JOIN cc_documenttypelang dtl ON dtl.documenttype_id = sa.documenttype_id AND dtl.language_id = lang.id
2354 LEFT JOIN cc_useraccess us ON us.id = sa.createdby_id;
2355
2356-- CONTACT EMAILS;
2357-- ##############################################################################################
2358CREATE OR REPLACE VIEW cc_contactemailview AS
2359 SELECT con.id,
2360 'C'::text AS contacttype,
2361 COALESCE(pa.name, COALESCE(p.name_short, p.name)) AS companyname,
2362 con.name,
2363 con.email,
2364 con.phone,
2365 con.phone2,
2366 pa.city,
2367 cou.language_id,
2368 cou.name AS countryname
2369 FROM cc_contact con
2370 LEFT JOIN cc_partyaddress pa ON pa.id = con.partyaddress_id
2371 LEFT JOIN cc_party p ON p.id = pa.party_id
2372 LEFT JOIN cc_countrylang cou ON cou.country_id = p.country_id
2373 WHERE con.email IS NOT NULL AND con.email::text <> ''::text
2374 UNION
2375 SELECT pa.id,
2376 'P'::text AS contacttype,
2377 COALESCE(pa.name, COALESCE(p.name_short, p.name)) AS companyname,
2378 NULL::character varying AS name,
2379 pa.email,
2380 pa.phone,
2381 NULL::character varying AS phone2,
2382 pa.city,
2383 cou.language_id,
2384 cou.name AS countryname
2385 FROM cc_partyaddress pa
2386 LEFT JOIN cc_party p ON p.id = pa.party_id
2387 LEFT JOIN cc_countrylang cou ON cou.country_id = p.country_id
2388 WHERE pa.email IS NOT NULL AND pa.email::text <> ''::text;
2389
2390-- INVOICE CONCEPTS FOR GROUPED INVOICES;
2391-- ##############################################################################################
2392CREATE OR REPLACE VIEW cc_invoiceconceptgroupedview AS
2393 SELECT COALESCE(f2.delegation_id, f.delegation_id) AS delegation_id,
2394 v.id,
2395 COALESCE(s.name, f.name) AS filename,
2396 v.file_id,
2397 v.shipment_id,
2398 v.customer_id,
2399 v.invoiceconcept_id,
2400 cus.invoicegroupmode,
2401 cus.issepoutlay,
2402 icl.name AS invoiceconceptname,
2403 ic.iatacharge,
2404 ic.iatachargeto,
2405 icl.language_id,
2406 v.units,
2407 v.price,
2408 v.currency_id,
2409 COALESCE(v.printorder, ic.printorder) AS printorder,
2410 v.printtext,
2411 v.invoicetax_id,
2412 il.name AS invoicetaxname,
2413 ft.transportmode,
2414 ft.trafficflow,
2415 ft.etd,
2416 ft.eta,
2417 CASE
2418 WHEN ft.trafficflow::text = 'I'::text THEN ft.eta
2419 ELSE ft.etd
2420 END AS valdate,
2421 ft.blnumber AS masterblnumber,
2422 cur.code AS currencycode,
2423 cur.decimals AS currencydecimals,
2424 cur.symbol AS currencysymbol,
2425 ict.isoutlayvat,
2426 CASE
2427 WHEN ft.transportmode != 'SEA' or (SELECT count(*) AS count
2428 FROM cc_filetrafficcontainer ftc
2429 WHERE ftc.filetraffic_id = ft.id) = 0 THEN ''
2430 WHEN (SELECT count(*) AS count
2431 FROM cc_filetrafficcontainer ftc
2432 WHERE ftc.filetraffic_id = ft.id) = 1 THEN ( SELECT DISTINCT ftc.containerplate
2433 FROM cc_filetrafficcontainer ftc
2434 WHERE ftc.filetraffic_id = ft.id)
2435 ELSE '+'::character varying
2436 END AS containerplate
2437 FROM cc_filevalsale v
2438 LEFT JOIN cc_shipment s ON s.id = v.shipment_id
2439 LEFT JOIN cc_file f ON f.id = v.file_id
2440 LEFT JOIN cc_file f2 ON f2.id = s.file_id
2441 LEFT JOIN cc_filetraffic ft ON ft.file_id = COALESCE(s.file_id, v.file_id)
2442 LEFT JOIN cc_invoiceconcept ic ON ic.id = v.invoiceconcept_id
2443 LEFT JOIN cc_invoiceconcepttype ict ON ict.id = ic.invoiceconcepttype_id
2444 LEFT JOIN cc_invoiceconceptlang icl ON icl.parent_id = v.invoiceconcept_id
2445 LEFT JOIN cc_partyaddress pa ON pa.id = v.customer_id
2446 LEFT JOIN cc_customer cus ON cus.party_id = pa.party_id
2447 LEFT JOIN cc_invoicetaxlang il ON il.language_id = icl.language_id AND il.parent_id = v.invoicetax_id
2448 LEFT JOIN cc_currency cur ON cur.id = v.currency_id
2449 WHERE v.isinvoice = 'N'::bpchar;
2450
2451-- FILE TRAFFIC COURIER
2452-- ##############################################################################################
2453CREATE OR REPLACE VIEW cc_filetrafficcour AS
2454 SELECT f.delegation_id,
2455 f.isactive,
2456 ft.id,
2457 f.id AS file_id,
2458 f.name AS filename,
2459 ft.trafficflow,
2460 ft.transportmode,
2461 ft.eta,
2462 ft.etd,
2463 ft.courieragent_id,
2464 COALESCE(pa.name, COALESCE(p.name_short, p.name)) AS courieragentname,
2465 ft.countryorigin_id,
2466 COALESCE(corl.name, cor.name) AS countryoriginname,
2467 ft.countrydestination_id,
2468 COALESCE(cdel.name, cde.name) AS countrydestinationname,
2469 ft.blnumber,
2470 ft.domesticshippingnumber,
2471 shp.customer_id,
2472 COALESCE(pca.name, COALESCE(pc.name_short, pc.name)) AS customername,
2473 shp.customerref,
2474 f.status,
2475 lan.id AS language_id,
2476 fs.isdangerous,
2477 fs.istemperaturecontrol,
2478 fs2.statusinvpurchase,
2479 fs2.statusinvsale,
2480 fs2.isrisk,
2481 fs2.isincident,
2482 f.risponsable_id,
2483 f.docrisponsable_id
2484 FROM cc_filetraffic ft
2485 LEFT JOIN cc_filetrafficsummary fs ON fs.filetraffic_id = ft.id
2486 LEFT JOIN cc_file f ON f.id = ft.file_id
2487 LEFT JOIN cc_filesummary fs2 ON fs2.file_id = ft.file_id
2488 LEFT JOIN cc_partyaddress pa ON pa.id = ft.courieragent_id
2489 LEFT JOIN cc_party p ON p.id = pa.party_id
2490 LEFT JOIN cc_shipment shp ON shp.file_id = ft.file_id
2491 LEFT JOIN cc_partyaddress pca ON pca.id = shp.customer_id
2492 LEFT JOIN cc_party pc ON pc.id = pca.party_id
2493 LEFT JOIN cc_language lan ON lan.isactive = 'Y'::bpchar
2494 LEFT JOIN cc_countrylang corl ON corl.country_id = ft.countryorigin_id AND corl.language_id = lan.id
2495 LEFT JOIN cc_country cor ON cor.id = ft.countryorigin_id
2496 LEFT JOIN cc_countrylang cdel ON cdel.country_id = ft.countrydestination_id AND cdel.language_id = lan.id
2497 LEFT JOIN cc_country cde ON cde.id = ft.countrydestination_id
2498 WHERE ft.transportmode::text = 'COUR'::text;
2499
2500
2501
2502-- COURIER AGENTS;
2503-- ##############################################################################################
2504CREATE OR REPLACE VIEW cc_courieragentview AS
2505 SELECT pa.id,
2506 COALESCE(pa.name, COALESCE(p.name_short, p.name)) AS name,
2507 CASE
2508 WHEN pa.isactive = 'N'::bpchar OR p.isactive = 'N'::bpchar THEN 'N'::text
2509 ELSE 'Y'::text
2510 END AS isactive
2511 FROM cc_partyaddress pa
2512 LEFT JOIN cc_party p ON p.id = pa.party_id
2513 WHERE p.iscourieragent = 'Y'::bpchar;
2514
2515
2516-- SALES REPRESENTATIVES;
2517-- ##############################################################################################
2518CREATE OR REPLACE VIEW cc_salesrepresentativesview AS
2519 SELECT pa.id,
2520 COALESCE(pa.name, COALESCE(p.name_short, p.name)) AS name,
2521 CASE
2522 WHEN pa.isactive = 'Y'::bpchar AND p.isactive = 'Y'::bpchar THEN 'Y'::text
2523 ELSE 'N'::text
2524 END AS isactive
2525 FROM cc_partyaddress pa
2526 LEFT JOIN cc_party p ON p.id = pa.party_id
2527 WHERE p.issalesrepresentative = 'Y'::bpchar;
2528
2529
2530-- Transport places by shipment and file;
2531-- ##############################################################################################
2532CREATE OR REPLACE VIEW cc_filetransportplacesview AS
2533 SELECT shp.id AS shipment_id,
2534 shp.file_id,
2535 shp.name,
2536 CASE
2537 WHEN un1.name IS NOT NULL AND un1.name::text <> ''::text THEN un1.name
2538 WHEN da1.city IS NOT NULL AND da1.city::text <> ''::text THEN da1.city
2539 WHEN da1.province IS NOT NULL AND da1.province::text <> ''::text THEN da1.province
2540 WHEN pa1.city IS NOT NULL AND pa1.city::text <> ''::text THEN pa1.city
2541 WHEN pa1.province IS NOT NULL AND pa1.province::text <> ''::text THEN pa1.province
2542 ELSE NULL::character varying
2543 END AS pickupplace,
2544 CASE
2545 WHEN un2.name IS NOT NULL AND un2.name::text <> ''::text THEN un2.name
2546 WHEN da2.city IS NOT NULL AND da2.city::text <> ''::text THEN da2.city
2547 WHEN da2.province IS NOT NULL AND da2.province::text <> ''::text THEN da2.province
2548 WHEN pa2.city IS NOT NULL AND pa2.city::text <> ''::text THEN pa2.city
2549 WHEN pa2.province IS NOT NULL AND pa2.province::text <> ''::text THEN pa2.province
2550 ELSE NULL::character varying
2551 END AS deliveryplace
2552 FROM cc_shipmenttraffic sht
2553 LEFT JOIN cc_unlocode un1 ON un1.id = sht.placereceipt_id
2554 LEFT JOIN cc_docaddress da1 ON da1.id = sht.shipperadd_id
2555 LEFT JOIN cc_partyaddress pa1 ON pa1.id = sht.pickuppartyaddress_id
2556 LEFT JOIN cc_unlocode un2 ON un2.id = sht.placedelivery_id
2557 LEFT JOIN cc_docaddress da2 ON da2.id = sht.consigneeadd_id
2558 LEFT JOIN cc_partyaddress pa2 ON pa2.id = sht.deliverypartyaddress_id
2559 LEFT JOIN cc_shipment shp ON shp.id = sht.shipment_id;
2560
2561-- CUSTOMER BL TEXT;
2562-- ##############################################################################################
2563CREATE OR REPLACE VIEW cc_bltextview AS
2564 SELECT t.delegation_id,
2565 t.id,
2566 t.shipper_id,
2567 COALESCE(pas.name, COALESCE(ps.name_short, ps.name)) AS shippername,
2568 t.consignee_id,
2569 COALESCE(pac.name, COALESCE(pc.name_short, pc.name)) AS consigneename,
2570 t.countrydestination_id,
2571 cl.name AS countrydestinationname,
2572 t.portdestination_id,
2573 ul.name AS portdestinationname,
2574 u.code AS portdestinationcode,
2575 t.customstariffheading,
2576 t.bltextapplication,
2577 t.printorder,
2578 t.summary,
2579 t.descriptionofgoods,
2580 t.isactive,
2581 lang.id AS language_id
2582 FROM cc_bltext t
2583 LEFT JOIN cc_language lang ON lang.isactive = 'Y'::bpchar
2584 LEFT JOIN cc_partyaddress pas ON pas.id = t.shipper_id
2585 LEFT JOIN cc_party ps ON ps.id = pas.party_id
2586 LEFT JOIN cc_partyaddress pac ON pac.id = t.consignee_id
2587 LEFT JOIN cc_party pc ON pc.id = pac.party_id
2588 LEFT JOIN cc_countrylang cl ON cl.language_id = lang.id AND cl.country_id = t.countrydestination_id
2589 LEFT JOIN cc_unlocodelang ul ON ul.language_id = lang.id AND ul.unlocode_id = t.portdestination_id
2590 LEFT JOIN cc_unlocode u ON u.id = t.portdestination_id;
2591
2592-- AWB TEXT VIEW;
2593-- ##############################################################################################
2594CREATE OR REPLACE VIEW cc_awbtextview AS
2595 SELECT t.id,
2596 t.delegation_id,
2597 t.airline_id,
2598 COALESCE(ps.name_short, ps.name) AS airlinename,
2599 t.airportdestination_id,
2600 ap.name AS airportdestinationname,
2601 t.accountinginfo,
2602 t.handlinginfo,
2603 t.isactive
2604 FROM cc_awbtext t
2605 LEFT JOIN cc_airline air ON air.id = t.airline_id
2606 LEFT JOIN cc_party ps ON ps.id = air.party_id
2607 LEFT JOIN cc_airport ap ON ap.id = t.airportdestination_id;
2608
2609-- PRINTERS VIEW;
2610-- ##############################################################################################
2611CREATE OR REPLACE VIEW cc_printerview AS
2612 SELECT p.id,
2613 l.id AS language_id,
2614 pl.name
2615 FROM cc_printer p
2616 LEFT JOIN cc_language l ON l.isactive = 'Y'::bpchar
2617 LEFT JOIN cc_printerlang pl ON pl.parent_id = p.id AND pl.language_id = l.id;
2618
2619-- FILE TRAFFIC INLAND
2620-- ##############################################################################################
2621CREATE OR REPLACE VIEW cc_filetrafficland AS
2622 SELECT f.delegation_id,
2623 f.isactive,
2624 ft.id,
2625 f.id AS file_id,
2626 f.name AS filename,
2627 ft.trafficflow,
2628 ft.transportmode,
2629 ft.trafficchargetype,
2630 ft.eta,
2631 ft.etd,
2632 ft.inlandcarrier_id,
2633 COALESCE(pa.name, COALESCE(p.name_short, p.name)) AS inlandcarriername,
2634 ft.origin_id,
2635 COALESCE(uorl.name, uor.name) AS originname,
2636 ft.destination_id,
2637 COALESCE(udel.name, ude.name) AS destinationname,
2638 ft.blnumber,
2639 shp.customer_id,
2640 COALESCE(pca.name, COALESCE(pc.name_short, pc.name)) AS customername,
2641 shp.customerref,
2642 f.status,
2643 lan.id AS language_id,
2644 fs.isdangerous,
2645 fs.istemperaturecontrol,
2646 fs2.statusinvpurchase,
2647 fs2.statusinvsale,
2648 fs2.isrisk,
2649 fs2.isincident,
2650 f.isfile,
2651 f.grmsyncstatus,
2652 ft.correspondent_id,
2653 COALESCE(co.name, COALESCE(pco.name_short, pco.name)) AS correspondentname
2654 , f.risponsable_id,
2655 f.docrisponsable_id, u1.name as risponsablename
2656, u2.name as docrisponsablename
2657 FROM cc_filetraffic ft
2658 LEFT JOIN cc_filetrafficsummary fs ON fs.filetraffic_id = ft.id
2659 LEFT JOIN cc_filesummary fs2 ON fs2.file_id = ft.file_id
2660 LEFT JOIN cc_file f ON f.id = ft.file_id
2661 LEFT JOIN cc_partyaddress pa ON pa.id = ft.inlandcarrier_id
2662 LEFT JOIN cc_party p ON p.id = pa.party_id
2663 LEFT JOIN cc_shipment shp ON shp.file_id = ft.file_id
2664 LEFT JOIN cc_partyaddress pca ON pca.id = shp.customer_id
2665 LEFT JOIN cc_party pc ON pc.id = pca.party_id
2666 LEFT JOIN cc_language lan ON lan.isactive = 'Y'::bpchar
2667 LEFT JOIN cc_unlocodelang uorl ON uorl.unlocode_id = ft.origin_id AND uorl.language_id = lan.id
2668 LEFT JOIN cc_unlocode uor ON uor.id = ft.origin_id
2669 LEFT JOIN cc_unlocodelang udel ON udel.unlocode_id = ft.destination_id AND udel.language_id = lan.id
2670 LEFT JOIN cc_unlocode ude ON ude.id = ft.destination_id
2671 LEFT JOIN cc_partyaddress co ON co.id = ft.correspondent_id
2672 LEFT JOIN cc_party pco ON pco.id = co.party_id
2673 LEFT JOIN cc_useraccess u1 on u1.id = f.risponsable_id
2674 LEFT JOIN cc_useraccess u2 on u2.id = f.docrisponsable_id
2675 WHERE ft.transportmode::text = 'LAND'::text;
2676
2677-- REPORTS;
2678-- ##############################################################################################
2679CREATE OR REPLACE VIEW cc_reportview AS
2680 SELECT r.id,
2681 r.reportcode,
2682 r.delegation_id,
2683 r.printer_id,
2684 r.defaultnumbertoprint,
2685 r.transportmode,
2686 r.trafficflow,
2687 r.onlyforuser_id,
2688 u.name AS username,
2689 prl.language_id,
2690 prl.name AS printername,
2691 pr.systemname AS printersystemname
2692 FROM cc_report r
2693 LEFT JOIN cc_useraccess u ON u.id = r.onlyforuser_id
2694 LEFT JOIN cc_printer pr ON pr.id = r.printer_id
2695 LEFT JOIN cc_printerlang prl ON prl.parent_id = r.printer_id;
2696
2697-- SHIPMENTS BY CONTAINER;
2698-- ##############################################################################################
2699CREATE OR REPLACE VIEW cc_shipmentsbycontainerview AS
2700 SELECT com.shipment_id,
2701 sbc.filetrafficcontainer_id
2702 FROM cc_shipmentbycontainer sbc
2703 LEFT JOIN cc_shipmentcomm com ON com.id = sbc.shipmentcommodity_id
2704 GROUP BY com.shipment_id, sbc.filetrafficcontainer_id
2705 ORDER BY com.shipment_id, sbc.filetrafficcontainer_id;
2706
2707-- FILE GENERAL;
2708-- ##############################################################################################
2709CREATE OR REPLACE VIEW cc_shipmentgeneralview AS
2710 SELECT shp.id AS file_id,
2711 shp.customer_id,
2712 shp.customerref,
2713 shp.name,
2714 f.filetype,
2715 f.status,
2716 f.risponsable_id,
2717 u.name AS risponsablename,
2718 CASE
2719 WHEN f.filetype::text = 'GEN'::text THEN fg.servicedate
2720 WHEN f.filetype::text = 'TRA'::text AND ft.trafficflow::text = 'E'::text THEN ft.etd
2721 WHEN f.filetype::text = 'TRA'::text AND ft.trafficflow::text = 'C'::text THEN ft.etd
2722 WHEN f.filetype::text = 'TRA'::text AND ft.trafficflow::text = 'I'::text THEN ft.eta
2723 ELSE NULL::timestamp without time zone
2724 END AS servicedate,
2725 COALESCE(pa.name, COALESCE(p.name_short, p.name)) AS customername,
2726 ss.statusinvpurchase,
2727 ss.statusinvsale,
2728 ft.transportmode,
2729 ft.trafficflow
2730 FROM
2731 cc_shipment shp
2732 LEFT JOIN cc_file f ON f.id = shp.file_id
2733 LEFT JOIN cc_filegeneral fg ON fg.file_id = f.id
2734 LEFT JOIN cc_filetraffic ft ON ft.file_id = f.id
2735 LEFT JOIN cc_shipmentsummary ss ON ss.shipment_id = shp.id
2736 LEFT JOIN cc_partyaddress pa ON pa.id = fg.customer_id
2737 LEFT JOIN cc_party p ON p.id = pa.party_id
2738 LEFT JOIN cc_useraccess u ON u.id = f.risponsable_id;
2739
2740
2741-- BOOKING CONTAINER HEADER - MESSAGE VIEW;
2742-- ##############################################################################################
2743CREATE OR REPLACE VIEW cc_bookingcontainermessageview AS
2744 SELECT f.delegation_id,
2745 br.id AS bookingcontainerheader_id,
2746 br.bookingnumber,
2747 fd.id AS filedocument_id,
2748 m.id AS messageedi_id,
2749 f.id AS file_id,
2750 ftr.shipagent_id,
2751 car.scaccode
2752 FROM cc_bookingcontainerheader br
2753 LEFT JOIN cc_filedocument fd ON fd.id = br.filedocument_id
2754 LEFT JOIN cc_file f ON f.id = fd.file_id
2755 LEFT JOIN cc_filetraffic ftr ON ftr.file_id = f.id
2756 LEFT JOIN cc_carrier car ON car.party_id = ftr.shippingline_id
2757 LEFT JOIN cc_messageedi m ON m.id = fd.messageedi_id;
2758
2759-- USER LOG VIEW;
2760-- ##############################################################################################
2761CREATE OR REPLACE VIEW cc_userlogview AS
2762 SELECT l.id,
2763 l.createddate,
2764 l.isactive,
2765 l.updateddate,
2766 l.detail,
2767 l.summary,
2768 l.createdby_id,
2769 l.updated_id,
2770 l.user_id,
2771 l.severity,
2772 l.originuser_id,
2773 us1.name AS originusername
2774 FROM cc_userlog l
2775 LEFT JOIN cc_useraccess us1 ON us1.id = l.originuser_id;
2776
2777-- MESSAGE EDI VIEW;
2778-- ##############################################################################################
2779CREATE OR REPLACE VIEW cc_messageediview AS
2780 SELECT m.delegation_id,
2781 m.id,
2782 m.messageplatform,
2783 m.messagestatus,
2784 COALESCE(COALESCE(m.datesent, m.datereceived), m.createddate) AS messagedate,
2785 m.datesent,
2786 m.datereceived,
2787 m.messagetype,
2788 m.file_id,
2789 m.shipment_id,
2790 m.messagereference,
2791 m.referencedmessage,
2792 m.error,
2793 CASE
2794 WHEN (select isfile from cc_file where id = f.id) = 'Y'
2795 THEN f.name
2796 WHEN (select isfile from cc_file where id = f.id) = 'N'
2797 THEN COALESCE(s.name, s2.name)
2798 WHEN (select isfile from cc_file where id = fref.id) = 'Y'
2799 THEN fref.name
2800 WHEN (select isfile from cc_file where id = fref.id) = 'N'
2801 THEN COALESCE(sref.name, sref2.name)
2802 END as filename,
2803 m.absolutefilepath
2804 FROM cc_messageedi m
2805 LEFT JOIN cc_file f ON f.id = m.file_id
2806 LEFT JOIN cc_shipment s ON s.id = m.shipment_id
2807 LEFT JOIN cc_shipment s2 ON s2.file_id = f.id
2808 LEFT JOIN cc_messageedi ref on ref.messagereference = m.referencedmessage
2809 LEFT JOIN cc_file fref ON fref.id = ref.file_id
2810 LEFT JOIN cc_shipment sref ON sref.id = ref.shipment_id
2811 LEFT JOIN cc_shipment sref2 ON sref2.file_id = fref.id;
2812
2813-- FILE TRAFFIC CONTAINER PORTIC TRACK AND TRACE;
2814-- ##############################################################################################
2815CREATE OR REPLACE VIEW cc_filetrafficcontainerportictt AS
2816 SELECT f.delegation_id,
2817 cnt.id AS filetrafficcontainer_id,
2818 cnt.containerplate,
2819 cnt.carrierreference,
2820 unl.code AS unlocode,
2821 ftr.trafficflow,
2822 bh.bookingnumber,
2823 ftr.blnumber,
2824 CASE
2825 WHEN ftr.trafficflow::text = 'I'::text THEN ftr.eta
2826 ELSE ftr.etd
2827 END AS estimateddate
2828 FROM cc_filetrafficcontainer cnt
2829 LEFT JOIN cc_filetraffic ftr ON ftr.id = cnt.filetraffic_id
2830 LEFT JOIN cc_file f ON f.id = ftr.file_id
2831 LEFT JOIN cc_unlocode unl ON unl.id =
2832 CASE
2833 WHEN ftr.trafficflow::text = 'I'::text THEN ftr.destination_id
2834 ELSE ftr.origin_id
2835 END
2836 LEFT JOIN cc_delegation del ON del.id = f.delegation_id
2837 LEFT JOIN cc_bookingcontainerheader bh ON bh.id = cnt.bookingcontainerheader_id
2838 WHERE (ftr.trafficflow::text = 'E'::text AND bh.bookingnumber IS NOT NULL OR ftr.trafficflow::text = 'I'::text AND ftr.blnumber IS NOT NULL) AND (ftr.trafficflow::text = 'E'::text AND ftr.etd > ('now'::text::date - '30 days'::interval) AND ftr.etd < ('now'::text::date + '40 days'::interval) OR ftr.trafficflow::text = 'I'::text AND ftr.eta > ('now'::text::date - '30 days'::interval) AND ftr.eta < ('now'::text::date + '40 days'::interval)) AND del.isporticconnected = 'Y'::bpchar;
2839
2840-- OPEN SHIPMENTS;
2841-- ##############################################################################################
2842CREATE OR REPLACE VIEW cc_shipmentopenview AS
2843 SELECT s.id,
2844 f.delegation_id,
2845 s.name,
2846 ftr.transportmode,
2847 ftr.trafficflow,
2848 f.id AS file_id
2849 FROM cc_shipment s
2850 LEFT JOIN cc_file f ON f.id = s.file_id
2851 LEFT JOIN cc_filetraffic ftr ON ftr.file_id = s.file_id
2852 WHERE f.status::text <> 'CLOSED'::text;
2853
2854
2855-- WAREHOUSE BY CONSOLIDATOR;
2856-- ##############################################################################################
2857CREATE OR REPLACE VIEW cc_warehousebyconsolidatorview AS
2858 SELECT wbc.id,
2859 wbc.consolidator_id,
2860 lan.id AS language_id,
2861 COALESCE(pac.name, COALESCE(pc.name_short, pc.name)) AS consolidatorname,
2862 wbc.warehouse_id,
2863 COALESCE(paw.name, COALESCE(pw.name_short, pw.name)) AS warehousename,
2864 wbc.localport_id,
2865 unl.name AS localportname
2866 FROM cc_warehousebyconsolidator wbc
2867 LEFT JOIN cc_partyaddress pac ON pac.id = wbc.consolidator_id
2868 LEFT JOIN cc_party pc ON pc.id = pac.party_id
2869 LEFT JOIN cc_partyaddress paw ON paw.id = wbc.warehouse_id
2870 LEFT JOIN cc_party pw ON pw.id = paw.party_id
2871 LEFT JOIN cc_language lan ON lan.isactive = 'Y'::bpchar
2872 LEFT JOIN cc_unlocodelang unl ON unl.unlocode_id = wbc.localport_id AND unl.language_id = lan.id;
2873
2874-- HANDLING AGENT BY AIRLINE
2875-- ##############################################################################################
2876CREATE OR REPLACE VIEW cc_handlingagentbyairlineview AS
2877 SELECT hba.id,
2878 hba.airline_id,
2879 airl.party_id AS airlineparty_id,
2880 hba.handlingagent_id,
2881 COALESCE(pah.name, COALESCE(ph.name_short, ph.name)) AS handlingagentname,
2882 hba.airport_id,
2883 air.code AS airportcode,
2884 air.name AS airportname
2885 FROM cc_handlingagentbyairline hba
2886 LEFT JOIN cc_airline airl ON airl.id = hba.airline_id
2887 LEFT JOIN cc_party pa ON pa.id = airl.party_id
2888 LEFT JOIN cc_partyaddress pah ON pah.id = hba.handlingagent_id
2889 LEFT JOIN cc_party ph ON ph.id = pah.party_id
2890 LEFT JOIN cc_airport air ON air.id = hba.airport_id;
2891
2892
2893-- PENDINGARRIVALVIEW;
2894-- ##############################################################################################
2895CREATE OR REPLACE VIEW cc_pendingarrivalview AS
2896 SELECT ft.id,
2897 ft.eta,
2898 CASE WHEN f.isfile = 'Y' then f.name ELSE (SELECT shp.name from cc_shipment shp where shp.file_id = f.id LIMIT 1) END as name,
2899 ft.transportmode,
2900 ft.trafficflow,
2901 ft.blnumber,
2902 fs.customername,
2903 lan.id AS language_id,
2904 CASE
2905 WHEN ft.transportmode::text = 'SEA'::text THEN ves.name
2906 WHEN ft.transportmode::text = 'AIR'::text THEN ft.flightnumber
2907 WHEN ft.transportmode::text = 'LAND'::text THEN ft.truckregistrationnumber
2908 WHEN ft.transportmode::text = 'COUR'::text THEN ft.domesticshippingnumber
2909 ELSE NULL::character varying
2910 END AS transportway,
2911 CASE
2912 WHEN ft.transportmode::text = 'SEA'::text THEN COALESCE(oril.name, ori.name)
2913 WHEN ft.transportmode::text = 'AIR'::text THEN aor.name
2914 WHEN ft.transportmode::text = 'LAND'::text THEN COALESCE(oril.name, ori.name)
2915 WHEN ft.transportmode::text = 'COUR'::text THEN COALESCE(corl.name, cor.name)
2916 ELSE NULL::character varying
2917 END AS originname,
2918 CASE
2919 WHEN ft.transportmode::text = 'SEA'::text THEN COALESCE(desl.name, des.name)
2920 WHEN ft.transportmode::text = 'AIR'::text THEN ades.name
2921 WHEN ft.transportmode::text = 'LAND'::text THEN COALESCE(desl.name, des.name)
2922 WHEN ft.transportmode::text = 'COUR'::text THEN COALESCE(cdel.name, cde.name)
2923 ELSE NULL::character varying
2924 END AS destinationname
2925 FROM cc_file f
2926 LEFT JOIN cc_filetraffic ft ON ft.file_id = f.id
2927 LEFT JOIN cc_filetrafficsummary fs ON fs.filetraffic_id = ft.id
2928 LEFT JOIN cc_language lan ON lan.isactive = 'Y'::bpchar
2929 LEFT JOIN cc_unlocode ori ON ori.id = ft.origin_id
2930 LEFT JOIN cc_unlocodelang oril ON oril.unlocode_id = ori.id AND oril.language_id = lan.id
2931 LEFT JOIN cc_unlocode des ON des.id = ft.destination_id
2932 LEFT JOIN cc_unlocodelang desl ON desl.unlocode_id = des.id AND desl.language_id = lan.id
2933 LEFT JOIN cc_vessel ves ON ves.id = ft.vessel_id
2934 LEFT JOIN cc_airport aor ON aor.id = ft.airportorigin_id
2935 LEFT JOIN cc_airport ades ON ades.id = ft.airportdestination_id
2936 LEFT JOIN cc_countrylang corl ON corl.country_id = ft.countryorigin_id AND corl.language_id = lan.id
2937 LEFT JOIN cc_country cor ON cor.id = ft.countryorigin_id
2938 LEFT JOIN cc_countrylang cdel ON cdel.country_id = ft.countrydestination_id AND cdel.language_id = lan.id
2939 LEFT JOIN cc_country cde ON cde.id = ft.countrydestination_id
2940 WHERE ft.transportmode::text = ANY (ARRAY['SEA'::character varying, 'AIR'::character varying, 'COUR'::character varying, 'LAND'::character varying]::text[]) AND CASE WHEN f.isfile = 'Y' then f.name ELSE (SELECT shp.name from cc_shipment shp where shp.file_id = f.id LIMIT 1) END IS NOT NULL;
2941
2942
2943-- party address area detail view;
2944-- ##############################################################################################
2945CREATE OR REPLACE VIEW cc_partyareadetailview AS
2946 SELECT a.id AS partyarea_id,
2947 a.party_id,
2948 a.name AS partyareaname,
2949 d.id,
2950 a.transportmode,
2951 lang.id AS language_id,
2952 d.country_id,
2953 d.port_id,
2954 d.location_id,
2955 d.airport_id,
2956 COALESCE(clul1.name, COALESCE(clul2.name, COALESCE(cla.name, cl.name))) AS countryname,
2957 u1.code AS portcode,
2958 ul1.name AS portname,
2959 s1.name AS portsubdivisionname,
2960 u2.code AS locationcode,
2961 ul2.name AS locationname,
2962 s2.name AS locationsubdivisionname,
2963 air.code AS airportcode,
2964 air.name AS airportname,
2965 a.responsible_id
2966 FROM cc_partyareadetail d
2967 LEFT JOIN cc_partyarea a ON a.id = d.partyarea_id
2968 LEFT JOIN cc_language lang ON lang.isactive = 'Y'::bpchar
2969 LEFT JOIN cc_countrylang cl ON cl.country_id = d.country_id AND cl.language_id = lang.id
2970 LEFT JOIN cc_unlocodelang ul1 ON ul1.unlocode_id = d.port_id AND ul1.language_id = lang.id
2971 LEFT JOIN cc_unlocode u1 ON u1.id = d.port_id
2972 LEFT JOIN cc_locationsubdivision s1 ON s1.id = u1.locationsubdivision_id
2973 LEFT JOIN cc_countrylang clul1 ON clul1.country_id = u1.country_id AND clul1.language_id = lang.id
2974 LEFT JOIN cc_airport air ON air.id = d.airport_id
2975 LEFT JOIN cc_countrylang cla ON cla.country_id = air.country_id AND cla.language_id = lang.id
2976 LEFT JOIN cc_unlocodelang ul2 ON ul2.unlocode_id = d.location_id AND ul2.language_id = lang.id
2977 LEFT JOIN cc_unlocode u2 ON u2.id = ul2.id
2978 LEFT JOIN cc_locationsubdivision s2 ON s2.id = u2.locationsubdivision_id
2979 LEFT JOIN cc_countrylang clul2 ON clul2.country_id = u2.country_id AND clul2.language_id = lang.id;
2980
2981-- contact view;
2982-- ##############################################################################################
2983CREATE OR REPLACE VIEW cc_contactview AS
2984 SELECT c.id,
2985 c.name,
2986 c.positionincompany,
2987 c.phone,
2988 c.phone2,
2989 c.email,
2990 c.partyaddress_id,
2991 pa.party_id,
2992 COALESCE(pa.name, COALESCE(p.name_short, p.name)) AS partyaddressname,
2993 pa.street,
2994 pa.city,
2995 pa.province,
2996 cd.name as departmentname
2997 FROM cc_contact c
2998 LEFT JOIN cc_partyaddress pa ON pa.id = c.partyaddress_id
2999 LEFT JOIN cc_party p ON p.id = pa.party_id
3000 LEFT JOIN cc_contact cd on cd.id = c.contactdepartment_id;
3001
3002-- pending fileval purchase view;
3003-- ##############################################################################################
3004CREATE OR REPLACE VIEW cc_filevalpurchasependingview AS
3005 SELECT fp.id,
3006 fp.shipment_id,
3007 shp.name AS shipmentname,
3008 fp.file_id,
3009 f.name AS filename,
3010 lang.id AS language_id,
3011 fp.vendor_id,
3012 p.fiscaladdress_id AS vendorfiscal_id,
3013 COALESCE(f.filetype, f2.filetype) AS filetype,
3014 CASE
3015 WHEN COALESCE(f.filetype, f2.filetype)::text = 'GEN'::text THEN fg.servicedate
3016 WHEN COALESCE(f.filetype, f2.filetype)::text = 'TRA'::text AND ftr.trafficflow::text = 'E'::text THEN ftr.etd
3017 WHEN COALESCE(f.filetype, f2.filetype)::text = 'TRA'::text AND ftr.trafficflow::text = 'C'::text THEN ftr.etd
3018 WHEN COALESCE(f.filetype, f2.filetype)::text = 'TRA'::text THEN ftr.eta
3019 ELSE f.datecreation
3020 END AS fileservicedate,
3021 ftr.transportmode,
3022 ftr.trafficflow,
3023 ftr.blnumber AS master,
3024 str.blnumber AS house,
3025 u1.code AS unlocodeorigincode,
3026 COALESCE(ul1.name, u1.name) AS unlocodeoriginname,
3027 u1.locationsubdivisioncode AS unlocodeoriginsubdivisioncode,
3028 COALESCE(coul1.name, cou1.name) AS unlocodeorigincountryname,
3029 u2.code AS unlocodedestinationcode,
3030 COALESCE(ul2.name, u2.name) AS unlocodedestinationname,
3031 u2.locationsubdivisioncode AS unlocodedestinationsubdivisioncode,
3032 COALESCE(coul2.name, cou2.name) AS unlocodedestinationcountryname,
3033 u3.code AS airportorigincode,
3034 u3.name AS airportoriginname,
3035 COALESCE(coul3.name, cou3.name) AS airportorigincountryname,
3036 u4.code AS airportdestinationcode,
3037 u4.name AS airportdestinationname,
3038 COALESCE(coul4.name, cou4.name) AS airportdestinationcountryname,
3039 cou5.code AS countryorigincode,
3040 COALESCE(coul5.name, cou5.name) AS countryoriginname,
3041 cou6.code AS countrydestinationcode,
3042 COALESCE(coul6.name, cou6.name) AS countrydestinationname,
3043 ic.id AS invoiceconcept_id,
3044 ict.isoutlayvat,
3045 il.name AS invoiceconceptname,
3046 cur.id AS currency_id,
3047 cur.decimals AS currencydecimals,
3048 cur.code AS currencycode,
3049 cur.symbol AS currencysymbol,
3050 fp.units,
3051 fp.price,
3052 fp.comments,
3053 fp.invoicetax_id,
3054 taxl.name AS invoicetaxname,
3055 tax.code AS taxcode,
3056 tax.percent AS taxpercent,
3057 CASE
3058 WHEN fp.shipment_id IS NOT NULL THEN ss.packages
3059 ELSE fs.packages
3060 END AS packages,
3061 CASE
3062 WHEN fp.shipment_id IS NOT NULL THEN ss.grossweight
3063 ELSE fs.grossweight
3064 END AS grossweight,
3065 CASE
3066 WHEN fp.shipment_id IS NOT NULL THEN ss.volume
3067 ELSE fs.volume
3068 END AS volume,
3069 CASE
3070 WHEN fp.shipment_id IS NOT NULL THEN ss.description
3071 ELSE fs.description
3072 END AS description,
3073 CASE
3074 WHEN fp.shipment_id IS NOT NULL THEN ss.containerplate
3075 ELSE fts.containerplate
3076 END AS containerplate,
3077 CASE
3078 WHEN fp.shipment_id IS NOT NULL THEN ss.containersnumber
3079 ELSE fts.numcont
3080 END AS numcont
3081 FROM cc_filevalpurchase fp
3082 LEFT JOIN cc_partyaddress pa ON pa.id = fp.vendor_id
3083 LEFT JOIN cc_party p ON p.id = pa.party_id
3084 LEFT JOIN cc_shipment shp ON shp.id = fp.shipment_id
3085 LEFT JOIN cc_shipmentsummary ss ON ss.shipment_id = fp.shipment_id
3086 LEFT JOIN cc_filesummary fs ON fs.id = fp.file_id
3087 LEFT JOIN cc_filetraffic ftr ON ftr.file_id = COALESCE(fp.file_id, shp.file_id)
3088 LEFT JOIN cc_filetrafficsummary fts ON fts.filetraffic_id = ftr.id
3089 LEFT JOIN cc_file f ON f.id = fp.file_id
3090 LEFT JOIN cc_shipmenttraffic str ON str.shipment_id = shp.id
3091 LEFT JOIN cc_file f2 ON f2.id = shp.file_id
3092 LEFT JOIN cc_language lang ON lang.isactive = 'Y'::bpchar
3093 LEFT JOIN cc_invoiceconceptlang il ON il.parent_id = fp.invoiceconcept_id AND il.language_id = lang.id
3094 LEFT JOIN cc_invoiceconcept ic ON ic.id = fp.invoiceconcept_id
3095 LEFT JOIN cc_invoiceconcepttype ict ON ict.id = ic.invoiceconcepttype_id
3096 LEFT JOIN cc_currency cur ON cur.id = fp.currency_id
3097 LEFT JOIN cc_unlocode u1 ON u1.id = ftr.origin_id
3098 LEFT JOIN cc_unlocodelang ul1 ON ul1.unlocode_id = u1.id AND ul1.language_id = lang.id
3099 LEFT JOIN cc_countrylang coul1 ON coul1.country_id = u1.country_id AND coul1.language_id = lang.id
3100 LEFT JOIN cc_country cou1 ON cou1.id = u1.country_id
3101 LEFT JOIN cc_invoicetaxlang taxl ON taxl.parent_id = fp.invoicetax_id AND taxl.language_id = lang.id
3102 LEFT JOIN cc_invoicetax tax ON tax.id = fp.invoicetax_id
3103 LEFT JOIN cc_unlocode u2 ON u2.id = ftr.destination_id
3104 LEFT JOIN cc_unlocodelang ul2 ON ul2.unlocode_id = u2.id AND ul2.language_id = lang.id
3105 LEFT JOIN cc_countrylang coul2 ON coul2.country_id = u2.country_id AND coul2.language_id = lang.id
3106 LEFT JOIN cc_country cou2 ON cou2.id = u2.country_id
3107 LEFT JOIN cc_airport u3 ON u3.id = ftr.airportorigin_id
3108 LEFT JOIN cc_countrylang coul3 ON coul3.country_id = u3.country_id AND coul3.language_id = lang.id
3109 LEFT JOIN cc_country cou3 ON cou3.id = u3.country_id
3110 LEFT JOIN cc_airport u4 ON u4.id = ftr.airportdestination_id
3111 LEFT JOIN cc_countrylang coul4 ON coul4.country_id = u4.country_id AND coul4.language_id = lang.id
3112 LEFT JOIN cc_country cou4 ON cou4.id = u4.country_id
3113 LEFT JOIN cc_country cou5 ON cou5.id = ftr.countryorigin_id
3114 LEFT JOIN cc_countrylang coul5 ON coul5.country_id = cou5.id AND coul5.language_id = lang.id
3115 LEFT JOIN cc_country cou6 ON cou6.id = ftr.countryorigin_id
3116 LEFT JOIN cc_countrylang coul6 ON coul6.country_id = cou6.id AND coul6.language_id = lang.id
3117 LEFT JOIN cc_filegeneral fg ON fg.file_id = COALESCE(fp.file_id, shp.file_id)
3118 WHERE fp.isinvoice = 'N'::bpchar;
3119
3120-- SALE INVOICE PURCHASE;
3121-- ##############################################################################################
3122CREATE OR REPLACE VIEW cc_purchaseinvoiceheaderview AS
3123 SELECT inv.delegation_id,
3124 inv.id,
3125 inv.name,
3126 inv.invoicedate,
3127 inv.invoicetype,
3128 inv.vendor_id,
3129 COALESCE(pa.name, COALESCE(p.name_short, p.name)) || ' (' || (SELECT to_char(pa.party_id, '999999999'::text)) || ')' AS vendorname,
3130 curl.language_id AS curlanguage_id,
3131 curl.name AS curname,
3132 cur.decimals AS curdecimals,
3133 cur.symbol AS cursymbol,
3134 inv.baseexempt,
3135 inv.basetax,
3136 inv.totalamount,
3137 inv.iscompleted,
3138 rin.name AS referencedinvoicename,
3139 inv.accountingstatus,
3140 inv.commentsinternal,
3141 inv.attachment_id,
3142 inv.completeddate,
3143 inv.iscancelled,
3144 inv.invoiceida3,
3145 inv.walletida3,
3146 COALESCE(ap.status, ap2.status) as accountingprocessstatus
3147 , COALESCE(ap.esoftcontafilename, ap2.esoftcontafilename) as esoftcontafilename
3148 , inv.ispayed
3149 ,
3150 ( SELECT due.duedate
3151 FROM cc_purchaseinvoiceduedate due
3152 WHERE due.parent_id = inv.id
3153 OFFSET 0
3154 LIMIT 1) AS duedate, inv.isoutlaysinvoice, pro.ishideinvoices
3155 , inv.datesenttoexternalsgd, inv.issenttoexternalsgd
3156 , inv.filename
3157 , CASE WHEN inv.currency_id = del.currency_id THEN inv.totalamount
3158 WHEN inv.exchange IS NOT NULL and inv.exchange <> 0 THEN ROUND(inv.totalamount * inv.exchange, cdel.decimals)
3159 ELSE ROUND(inv.totalamount * COALESCE((SELECT ice.exchange FROM cc_currencyexchange ice where ice.currencyfrom_id = inv.currency_id
3160 and ice.currencyto_id = del.currency_id and ice.exchangedate <= inv.invoicedate ORDER BY ice.exchange DESC limit 1), 0), cdel.decimals) END AS delegationtotalamount
3161 FROM cc_purchaseinvoiceheader inv
3162 LEFT JOIN cc_partyaddress pa ON pa.id = inv.vendor_id
3163 LEFT JOIN cc_party p ON p.id = pa.party_id
3164 LEFT JOIN cc_currency cur ON cur.id = inv.currency_id
3165 LEFT JOIN cc_currencylang curl ON curl.parent_id = cur.id
3166 LEFT JOIN cc_purchaseinvoiceheader rin ON rin.id = inv.referencedinvoice_id
3167 LEFT JOIN cc_accountingentry ae ON ae.id = inv.accountingentry_id
3168 LEFT JOIN cc_accountingprocess ap on ap.id = ae.accountingprocessheader_id
3169 LEFT JOIN cc_accountingprocess ap2 on ap2.id = inv.accountingprocess_id
3170 LEFT JOIN cc_delegation del on del.id = inv.delegation_id
3171 LEFT JOIN cc_provider pro on pro.party_id = pa.party_id
3172 LEFT JOIN cc_currency cdel on cdel.id = del.currency_id;
3173
3174
3175
3176
3177-- PURCHASE INVOICE DETAIL;
3178-- ##############################################################################################
3179CREATE OR REPLACE VIEW cc_purchaseinvoicedetailview AS
3180 SELECT d.id,
3181 d.parent_id AS purchaseinvoiceheader_id,
3182 d.units,
3183 d.price,
3184 d.invoicetax_id,
3185 CASE
3186 WHEN d.printtext IS NOT NULL AND length(btrim(d.printtext::text)) > 0 THEN d.printtext
3187 ELSE icl.name
3188 END AS name,
3189 d.filevalpurchase_id,
3190 v.invoiceconcept_id,
3191 d.currency_id,
3192 cur.code AS currencycode,
3193 cur.decimals AS curdecimals,
3194 COALESCE(cur.symbol, cur.code) AS currencysymbol,
3195 lan.id AS language_id,
3196 itl.name AS invoicetaxname,
3197 h.currency_id AS headercurrency_id,
3198 COALESCE(d.exchange, exc.exchange) AS exchange,
3199 hcur.decimals AS curheaderdecimals,
3200 ict.isoutlayvat,
3201 COALESCE(s.name, f.name) AS filename,
3202 ft.blnumber AS masterbl,
3203 d.shipment_id,
3204 d.file_id,
3205 v.vendor_id,
3206 d.istaxpit
3207 FROM cc_purchaseinvoicedetail d
3208 LEFT JOIN cc_purchaseinvoiceheader h ON h.id = d.parent_id
3209 LEFT JOIN cc_filevalpurchase v ON v.id = d.filevalpurchase_id
3210 LEFT JOIN cc_currency cur ON cur.id = d.currency_id
3211 LEFT JOIN cc_language lan ON lan.id > 0
3212 LEFT JOIN cc_invoicetaxlang itl ON itl.parent_id = d.invoicetax_id AND itl.language_id = lan.id
3213 LEFT JOIN cc_invoiceconceptlang icl ON icl.parent_id = v.invoiceconcept_id AND icl.language_id = lan.id
3214 LEFT JOIN cc_invoiceconcept ic ON ic.id = v.invoiceconcept_id
3215 LEFT JOIN cc_invoiceconcepttype ict ON ict.id = ic.invoiceconcepttype_id
3216 LEFT JOIN cc_purchaseinvoicecurrencyexchange exc ON exc.purchaseinvoiceheader_id = d.parent_id AND exc.currencyfrom_id = d.currency_id
3217 LEFT JOIN cc_currency hcur ON hcur.id = h.currency_id
3218 LEFT JOIN cc_file f ON f.id = d.file_id
3219 LEFT JOIN cc_shipment s ON s.id = d.shipment_id
3220 LEFT JOIN cc_filetraffic ft ON ft.file_id = COALESCE(s.file_id, f.id);
3221
3222-- OPEN FILES;
3223-- ##############################################################################################
3224CREATE OR REPLACE VIEW cc_fileopenview AS
3225 SELECT f.id,
3226 f.delegation_id,
3227 f.name,
3228 ftr.transportmode,
3229 ftr.trafficflow
3230 FROM cc_file f
3231 LEFT JOIN cc_filetraffic ftr ON ftr.file_id = f.id
3232 WHERE f.status::text <> 'CLOSED'::text;
3233
3234-- ACCOUNTING SUBACCOUNTS;
3235-- ##############################################################################################
3236CREATE OR REPLACE VIEW cc_subaccountsplanview AS
3237 SELECT s.company_id,
3238 p.name AS accountingplanname,
3239 COALESCE(a.name_short, a.name) AS accountsplanname,
3240 s.name AS subaccountsplanname,
3241 s.name_short AS subaccountsplanname_short,
3242 s.id,
3243 a.id AS accountsplan_id,
3244 p.id AS accountingplan_id,
3245 a.code AS accountcode,
3246 s.code AS subaccountcode,
3247 s.subaccounttype
3248 FROM cc_subaccountsplan s
3249 LEFT JOIN cc_accountsplan a ON a.id = s.accountsplan_id
3250 LEFT JOIN cc_accountingplan p ON p.id = a.accountingplan_id;
3251
3252-- ACCOUNTING VIEW;
3253-- ##############################################################################################
3254CREATE OR REPLACE VIEW cc_accountingplanview AS
3255 SELECT p.id,
3256 p.name,
3257 p.accountcustomers_id,
3258 COALESCE(a1.name_short, a1.name) AS accountcustomersname,
3259 p.accountdebtors_id,
3260 COALESCE(a2.name_short, a2.name) AS accountdebtorsname,
3261 p.accountproviders_id,
3262 COALESCE(a3.name_short, a3.name) AS accountprovidersname,
3263 p.accountcreditors_id,
3264 COALESCE(a4.name_short, a4.name) AS accountcreditorsname
3265 FROM cc_accountingplan p
3266 LEFT JOIN cc_accountsplan a1 ON a1.accountingplan_id = p.id AND a1.id = p.accountcustomers_id
3267 LEFT JOIN cc_accountsplan a2 ON a2.accountingplan_id = p.id AND a2.id = p.accountdebtors_id
3268 LEFT JOIN cc_accountsplan a3 ON a3.accountingplan_id = p.id AND a3.id = p.accountproviders_id
3269 LEFT JOIN cc_accountsplan a4 ON a4.accountingplan_id = p.id AND a4.id = p.accountcreditors_id;
3270
3271
3272-- CUSTOMS ORDER VIEW;
3273-- ##############################################################################################
3274CREATE OR REPLACE VIEW cc_customsorderview AS
3275 SELECT co.id,
3276 sd.shipment_id,
3277 co.customsbroker_id,
3278 co.shipmentdocument_id,
3279 COALESCE(pa.name, COALESCE(p.name_short, p.name)) AS customsbrokername,
3280 co.customsdocumenttype,
3281 co.documentdate,
3282 co.customsstatus,
3283 co.customsresult,
3284 co.sadreference,
3285 co.admissiondate,
3286 co.releasedate
3287 FROM cc_customsorderheader co
3288 LEFT JOIN cc_partyaddress pa ON pa.id = co.customsbroker_id
3289 LEFT JOIN cc_party p ON p.id = pa.party_id
3290 LEFT JOIN cc_shipmentdocument sd ON sd.id = co.shipmentdocument_id;
3291
3292-- DEPARTMENT VIEW;
3293-- ##############################################################################################
3294CREATE OR REPLACE VIEW cc_departmentview AS
3295 SELECT d.id,
3296 d.delegation_id,
3297 d.transportmode,
3298 d.trafficflow,
3299 d.supervisor_id,
3300 u.name AS supervisorname,
3301 dl.language_id,
3302 dl.name,
3303 d.parentdepartment_id
3304 FROM cc_department d
3305 LEFT JOIN cc_useraccess u ON u.id = d.supervisor_id
3306 LEFT JOIN cc_departmentlang dl ON dl.department_id = d.id;
3307
3308
3309-- INCIDENT TYPE VIEW;
3310-- ##############################################################################################
3311CREATE OR REPLACE VIEW cc_incidenttypeview AS
3312 SELECT i.id,
3313 i.id AS incidenttype_id,
3314 i.company_id,
3315 il.language_id,
3316 il.name, i.severitylevel_id, sl.name as severitylevelname
3317 FROM cc_incidenttype i
3318 LEFT JOIN cc_incidenttypelang il ON il.incidenttype_id = i.id
3319 LEFT JOIN cc_incidentseveritylevellang sl ON sl.incidentseveritylevel_id = i.severitylevel_id AND sl.language_id = il.language_id;
3320
3321
3322-- INCIDENT SEVERITY LEVEL VIEW;
3323-- ##############################################################################################
3324CREATE OR REPLACE VIEW cc_incidentseveritylevelview AS
3325 SELECT i.id,
3326 i.id AS incidentseveritylevel_id,
3327 i.company_id,
3328 i.color,
3329 i.backgroundcolor,
3330 il.language_id,
3331 il.name,
3332 il.description,
3333 i.levelvalue
3334 FROM cc_incidentseveritylevel i
3335 LEFT JOIN cc_incidentseveritylevellang il ON il.incidentseveritylevel_id = i.id;
3336
3337-- INCIDENT PROBABILITY;
3338-- ##############################################################################################
3339CREATE OR REPLACE VIEW cc_incidentprobabilityview AS
3340 SELECT i.id,
3341 i.id AS incidentprobability_id,
3342 i.company_id,
3343 il.language_id,
3344 il.name,
3345 il.description,
3346 i.levelvalue
3347 FROM cc_incidentprobability i
3348 LEFT JOIN cc_incidentprobabilitylang il ON il.incidentprobability_id = i.id;
3349
3350-- USER BY DEPARTMENT;
3351-- ##############################################################################################
3352CREATE OR REPLACE VIEW cc_userbydepartmentview AS
3353 SELECT ud.id,
3354 ru.delegation_id,
3355 ud.rolebyuser_id,
3356 ud.department_id,
3357 ru.user_id,
3358 u.name AS username,
3359 rl.language_id,
3360 CASE WHEN rl.nametoshowinorganigram IS NOT NULL AND length(trim(rl.nametoshowinorganigram)) > 0 THEN nametoshowinorganigram ELSE rl.name END AS rolename
3361 FROM cc_userbydepartment ud
3362 LEFT JOIN cc_rolebyuser ru ON ru.id = ud.rolebyuser_id
3363 LEFT JOIN cc_useraccess u ON u.id = ru.user_id
3364 LEFT JOIN cc_rolelang rl ON rl.role_id = ru.role_id;
3365
3366-- USERS BY DELEGATION;
3367-- ##############################################################################################
3368CREATE OR REPLACE VIEW cc_usersbydelegationview AS
3369 SELECT ru.id,
3370 u.name,
3371 ru.delegation_id,
3372 rl.language_id,
3373 rl.name AS rolename
3374 FROM cc_rolebyuser ru
3375 LEFT JOIN cc_useraccess u ON u.id = ru.user_id
3376 LEFT JOIN cc_rolelang rl ON rl.role_id = ru.role_id
3377 WHERE ru.isactive = 'Y'::bpchar AND u.isactive = 'Y'::bpchar;
3378
3379-- RISK VECTORS;
3380-- ##############################################################################################
3381CREATE OR REPLACE VIEW cc_riskvectorview AS
3382 SELECT i.id,
3383 i.id AS riskvector_id,
3384 i.company_id,
3385 il.language_id,
3386 il.name
3387 FROM cc_riskvector i
3388 LEFT JOIN cc_riskvectorlang il ON il.riskvector_id = i.id;
3389
3390-- RISK AFFECTATIONS;
3391-- ##############################################################################################
3392CREATE OR REPLACE VIEW cc_riskaffectationview AS
3393 SELECT i.id,
3394 i.id AS riskaffectation_id,
3395 i.company_id,
3396 il.language_id,
3397 il.name
3398 FROM cc_riskaffectation i
3399 LEFT JOIN cc_riskaffectationlang il ON il.riskaffectation_id = i.id;
3400
3401-- RISKS ;
3402-- ##############################################################################################
3403CREATE OR REPLACE VIEW cc_riskview AS
3404 SELECT r.delegation_id,
3405 l.id AS language_id,
3406 r.id,
3407 r.riskvector_id,
3408 rvl.name AS riskvectorname,
3409 r.riskaffectation_id,
3410 rfl.name AS riskaffectationname,
3411 r.severitylevel_id,
3412 sll.name AS severitylevelname,
3413 r.probability_id,
3414 ipl.name AS probabilityname,
3415 r.description,
3416 r.comments,
3417 r.status,
3418 r.correctionsrequired,
3419 sl.color,
3420 sl.backgroundcolor,
3421 r.file_id,
3422 CASE WHEN f.isfile = 'Y' THEN f.name ELSE (SELECT shp.name from cc_shipment shp where shp.file_id = f.id LIMIT 1) END AS filename,
3423 ftr.transportmode,
3424 ftr.trafficflow,
3425 ( SELECT count(*) AS count
3426 FROM cc_correctiveaction
3427 WHERE cc_correctiveaction.risk_id = r.id) AS numcorrectiveactions
3428 FROM cc_risk r
3429 LEFT JOIN cc_language l ON l.isactive = 'Y'::bpchar
3430 LEFT JOIN cc_riskvectorlang rvl ON rvl.id = r.riskvector_id AND rvl.language_id = l.id
3431 LEFT JOIN cc_riskaffectationlang rfl ON rfl.riskaffectation_id = r.riskaffectation_id AND rfl.language_id = l.id
3432 LEFT JOIN cc_incidentseveritylevellang sll ON sll.incidentseveritylevel_id = r.severitylevel_id AND sll.language_id = l.id
3433 LEFT JOIN cc_incidentseveritylevel sl ON sl.id = r.severitylevel_id
3434 LEFT JOIN cc_incidentprobabilitylang ipl ON ipl.incidentprobability_id = r.probability_id AND ipl.language_id = l.id
3435 LEFT JOIN cc_file f ON f.id = r.file_id
3436 LEFT JOIN cc_filetraffic ftr ON ftr.file_id = f.id;
3437
3438-- CORRECTIVE ACTIONS;
3439-- ##############################################################################################
3440CREATE OR REPLACE VIEW cc_correctiveactionview AS
3441 SELECT COALESCE(r.delegation_id, f.delegation_id) AS delegation_id,
3442 f.id AS file_id,
3443
3444 CASE WHEN f.isfile = 'Y' THEN f.name ELSE (select shp.name from cc_shipment shp where shp.file_id = f.id LIMIT 1) END AS filename,
3445 ca.id,
3446 ca.incident_id,
3447 ca.risk_id,
3448 ca.description,
3449 ca.correctionsrequired,
3450 ca.actionsuccessful,
3451 ca.status,
3452 r.description AS riskdescription,
3453 r.status AS riskstatus,
3454 i.description AS incidentdescription,
3455 i.status AS incidentstatus
3456 , ca.attachment1_id, ca.attachment2_id,
3457 ca.attachment3_id, ca.attachment4_id,
3458 ca.attachment5_id
3459 FROM cc_correctiveaction ca
3460 LEFT JOIN cc_risk r ON r.id = ca.risk_id
3461 LEFT JOIN cc_incident i ON i.id = ca.incident_id
3462 LEFT JOIN cc_file f ON f.id = COALESCE(r.file_id, i.file_id);
3463
3464-- INCIDENTS;
3465-- ##############################################################################################
3466CREATE OR REPLACE VIEW cc_incidentview AS
3467 SELECT i.id,
3468 f.id AS file_id,
3469 f.delegation_id,
3470 i.responsible_id,
3471 u.name AS responsiblename,
3472 CASE WHEN f.isfile = 'Y' THEN f.name ELSE (SELECT shp.name from cc_shipment shp where shp.file_id = f.id LIMIT 1) END AS filename,
3473 lang.id AS language_id,
3474 i.incidenttype_id,
3475 itl.name AS incidenttypename,
3476 i.correctionsrequired,
3477 i.severitylevel_id,
3478 sl.color,
3479 sl.backgroundcolor,
3480 sl.levelvalue,
3481 sll.name AS severitylevelname,
3482 sll.description AS severityleveldescription,
3483 i.procedence,
3484 i.dateincident,
3485 i.status,
3486 i.description,
3487 ftr.transportmode,
3488 ftr.trafficflow,
3489 str.isgdp
3490 , i.photography1_id, i.photography2_id, i.photography3_id
3491 , i.photography4_id, i.photography5_id
3492 , at1.filename as filename1, at1.filepath as filepath1
3493 , at2.filename as filename2, at2.filepath as filepath2
3494 , at3.filename as filename3, at3.filepath as filepath3
3495 , at4.filename as filename4, at4.filepath as filepath4
3496 , at5.filename as filename5, at5.filepath as filepath5
3497 , i.departmentisgdp
3498 FROM cc_incident i
3499 LEFT JOIN cc_language lang ON lang.isactive = 'Y'::bpchar
3500 LEFT JOIN cc_incidenttypelang itl ON itl.language_id = lang.id AND itl.incidenttype_id = i.incidenttype_id
3501 LEFT JOIN cc_file f ON f.id = i.file_id
3502 LEFT JOIN cc_filetraffic ftr ON ftr.file_id = f.id
3503 LEFT JOIN cc_useraccess u ON u.id = i.responsible_id
3504 LEFT JOIN cc_incidentseveritylevel sl ON sl.id = i.severitylevel_id
3505 LEFT JOIN cc_incidentseveritylevellang sll ON sll.incidentseveritylevel_id = sl.id AND sll.language_id = lang.id
3506 LEFT JOIN cc_attachment at1 on at1.id = i.photography1_id
3507 LEFT JOIN cc_attachment at2 on at2.id = i.photography2_id
3508 LEFT JOIN cc_attachment at3 on at3.id = i.photography3_id
3509 LEFT JOIN cc_attachment at4 on at4.id = i.photography4_id
3510 LEFT JOIN cc_attachment at5 on at5.id = i.photography5_id
3511 LEFT JOIN cc_shipment s on s.file_id = i.file_id
3512 LEFT JOIN cc_shipmenttraffic str on str.shipment_id = s.id;
3513
3514
3515-- DELEGATION LEGAL TEXTS;
3516-- ##############################################################################################
3517CREATE OR REPLACE VIEW cc_companylegaltextview AS
3518 SELECT dt.id,
3519 dt.company_id,
3520 l.id AS language_id,
3521 l.name AS languagename,
3522 dt.invoicefooterliability1,
3523 dt.invoicefooterliability2,
3524 dt.invoicefooterliability3,
3525 dt.invoicefootercustomerinfo,
3526 dt.houseblconditionsleft,
3527 dt.houseblconditionsright,
3528 dt.bookingconfirmation,
3529 dt.confirmationonboard,
3530 dt.avisollegada,
3531 dt.preavisollegada,
3532 dt.entreguese,
3533 dt.ordendespacho,
3534 dt.commercialoffer,
3535 dt.commercialofferconditions,
3536 dt.invoiceivaexport,
3537 dt.invoiceivaimport,
3538 dt.invoiceivacommunity,
3539 dt.invoiceivanoncommunity
3540 FROM cc_language l
3541 LEFT JOIN cc_companylegaltext dt ON dt.language_id = l.id;
3542
3543-- USERS;
3544-- ##############################################################################################
3545CREATE OR REPLACE VIEW cc_useraccessview AS
3546 SELECT lang.id AS language_id,
3547 ru.delegation_id,
3548 u.id,
3549 u.code,
3550 u.name,
3551 u.email,
3552 u.isactive,
3553 u.status,
3554 u.activefrom,
3555 u.activeto,
3556 at.filedata,
3557 at.contenttype,
3558 ( SELECT array_to_string(ARRAY( SELECT DISTINCT rl.name
3559 FROM cc_rolelang rl
3560 WHERE rl.role_id = ru.role_id AND rl.language_id = lang.id), ','::text, '*'::text) AS array_to_string) AS rolename
3561 FROM cc_rolebyuser ru
3562 LEFT JOIN cc_language lang ON lang.isactive = 'Y'::bpchar
3563 LEFT JOIN cc_useraccess u ON u.id = ru.user_id
3564 LEFT JOIN cc_useraccess sup ON sup.id = u.supervisor_id
3565 LEFT JOIN cc_attachment at ON at.id = u.photography_id;
3566
3567-- USER DOCUMENTS;
3568-- ##############################################################################################
3569CREATE OR REPLACE VIEW cc_userdocumentview AS
3570 SELECT ud.id,
3571 lang.id AS language_id,
3572 ud.user_id,
3573 ud.documenttype_id,
3574 ud.documentname,
3575 ud.documentdate,
3576 at.filename AS originalfilename,
3577 at.contenttype,
3578 ud.comments,
3579 at.filepath AS absolutefilepath,
3580 dtl.name AS documenttypename,
3581 ud.attachment_id
3582 FROM cc_userdocument ud
3583 LEFT JOIN cc_language lang ON lang.isactive = 'Y'::bpchar
3584 LEFT JOIN cc_documenttypelang dtl ON dtl.documenttype_id = ud.documenttype_id AND dtl.language_id = lang.id
3585 LEFT JOIN cc_attachment at ON at.id = ud.attachment_id;
3586
3587-- DELEGATION DOCUMENTS;
3588-- ##############################################################################################
3589CREATE OR REPLACE VIEW cc_delegationdocumentview AS
3590 SELECT ud.id,
3591 lang.id AS language_id,
3592 ud.delegation_id,
3593 ud.documenttype_id,
3594 ud.documentname,
3595 ud.documentdate,
3596 at.filename AS originalfilename,
3597 at.contenttype,
3598 ud.comments,
3599 at.filepath AS absolutefilepath,
3600 dtl.name AS documenttypename,
3601 ud.attachment_id,
3602 ud.mandatoryread
3603 FROM cc_delegationdocument ud
3604 LEFT JOIN cc_language lang ON lang.isactive = 'Y'::bpchar
3605 LEFT JOIN cc_documenttypelang dtl ON dtl.documenttype_id = ud.documenttype_id AND dtl.language_id = lang.id
3606 LEFT JOIN cc_attachment at ON at.id = ud.attachment_id;
3607
3608-- COMPANY DOCUMENTS;
3609-- ##############################################################################################
3610CREATE OR REPLACE VIEW cc_companydocumentview AS
3611 SELECT ud.id,
3612 lang.id AS language_id,
3613 ud.company_id,
3614 ud.documenttype_id,
3615 ud.documentname,
3616 ud.documentdate,
3617 at.filename AS originalfilename,
3618 at.contenttype,
3619 ud.comments,
3620 at.filepath AS absolutefilepath,
3621 dtl.name AS documenttypename,
3622 ud.attachment_id, ud.mandatoryread
3623 FROM cc_companydocument ud
3624 LEFT JOIN cc_language lang ON lang.isactive = 'Y'::bpchar
3625 LEFT JOIN cc_documenttypelang dtl ON dtl.documenttype_id = ud.documenttype_id AND dtl.language_id = lang.id
3626 LEFT JOIN cc_attachment at ON at.id = ud.attachment_id;
3627
3628-- PARTY DOCUMENTS;
3629-- ##############################################################################################
3630CREATE OR REPLACE VIEW cc_partydocumentview AS
3631 SELECT ud.id,
3632 lang.id AS language_id,
3633 ud.party_id,
3634 ud.documenttype_id,
3635 ud.documentname,
3636 ud.documentdate,
3637 at.filename AS originalfilename,
3638 at.contenttype,
3639 ud.comments,
3640 at.filepath AS absolutefilepath,
3641 dtl.name AS documenttypename,
3642 ud.attachment_id
3643 FROM cc_partydocument ud
3644 LEFT JOIN cc_language lang ON lang.isactive = 'Y'::bpchar
3645 LEFT JOIN cc_documenttypelang dtl ON dtl.documenttype_id = ud.documenttype_id AND dtl.language_id = lang.id
3646 LEFT JOIN cc_attachment at ON at.id = ud.attachment_id;
3647
3648-- CORPORATE DOCUMENTS;
3649-- ##############################################################################################
3650CREATE OR REPLACE VIEW cc_corporatedocuments AS
3651 SELECT d.attachment_id AS id,
3652 lang.id AS language_id,
3653 del.company_id,
3654 d.delegation_id,
3655 d.documentname,
3656 d.documentdate,
3657 d.comments,
3658 dt.name AS documenttypename
3659 , 'DELEGATION' as scope
3660 , d.id as entitydocument_id, d.mandatoryread
3661 FROM cc_delegationdocument d
3662 LEFT JOIN cc_delegation del ON del.id = d.delegation_id
3663 LEFT JOIN cc_language lang ON lang.isactive = 'Y'::bpchar
3664 LEFT JOIN cc_documenttypelang dt ON dt.documenttype_id = d.documenttype_id AND dt.language_id = lang.id
3665 UNION
3666 SELECT d.attachment_id AS id,
3667 lang.id AS language_id,
3668 d.company_id,
3669 NULL::integer AS delegation_id,
3670 d.documentname,
3671 d.documentdate,
3672 d.comments,
3673 dt.name AS documenttypename, 'COMPANY' as scope
3674 , d.id as entitydocument_id, d.mandatoryread
3675 FROM cc_companydocument d
3676 LEFT JOIN cc_language lang ON lang.isactive = 'Y'::bpchar
3677 LEFT JOIN cc_documenttypelang dt ON dt.documenttype_id = d.documenttype_id AND dt.language_id = lang.id;
3678
3679-- PREVENTIVE ACTIONS;
3680-- ##############################################################################################
3681CREATE OR REPLACE VIEW cc_preventiveactionview AS
3682 SELECT a.id,
3683 a.datepreventiveaction,
3684 a.identifiedby,
3685 a.responsible_id,
3686 a.description,
3687 a.tracing,
3688 a.actionsuccessful,
3689 a.status,
3690 a.closingdate,
3691 u.name AS responsiblename
3692 FROM cc_preventiveaction a
3693 LEFT JOIN cc_useraccess u ON u.id = a.responsible_id;
3694
3695-- TRACK AND TRACE EVENTS;
3696-- ##############################################################################################
3697CREATE OR REPLACE VIEW cc_trackandtraceeventview AS
3698 SELECT t.id,
3699 t.scope,
3700 t.porticcode,
3701 t.inttracode,
3702 t.valenciaportcode,
3703 t.isseafreight,
3704 t.isairfreight,
3705 t.iscourierfreight,
3706 t.islandfreight,
3707 tl.name,
3708 tl.description,
3709 tl.language_id,
3710 t.edinotificationaction,
3711 t.icon,
3712 t.styleclass,
3713 t.isreeferchamber,
3714 t.isshowtransportroute
3715 FROM cc_trackandtraceevent t
3716 LEFT JOIN cc_trackandtraceeventlang tl ON tl.trackandtraceevent_id = t.id;
3717
3718-- TRANSPORT ROUTES;
3719-- ##############################################################################################
3720CREATE OR REPLACE VIEW cc_transportrouteview AS
3721 SELECT r.id,
3722 lang.id AS language_id,
3723 r.transportmode,
3724 r.trafficflow,
3725 r.customer_id,
3726 COALESCE(pa.name, COALESCE(p.name_short, p.name)) AS customername,
3727 i.code as incotermcode
3728 , tr.tempmin, tr.tempmax, r.temperature, r.temperatureunit, r.description, r.status, r.trafficchargetype,
3729 r.validateddate, r.evaluationpoints, r.evaluationcompleted, r.validatedby, r.portorigin_id,
3730 r.portdestination_id, r.airportorigin_id, r.airportdestination_id, r.landorigin_id, r.landdestination_id,
3731 CASE WHEN r.transportmode = 'SEA' THEN COALESCE(pol.name, po.name) WHEN r.transportmode = 'AIR' THEN ao.name ELSE
3732 lo.name END AS origin
3733 , CASE WHEN r.transportmode = 'SEA' THEN COALESCE(pdl.name, pd.name) WHEN r.transportmode = 'AIR' THEN ad.name
3734 ELSE ld.name END as destination
3735 FROM cc_transportroute r
3736 LEFT JOIN cc_language lang ON lang.isactive = 'Y'::bpchar
3737 LEFT JOIN cc_partyaddress pa ON pa.id = r.customer_id
3738 LEFT JOIN cc_party p ON p.id = pa.party_id
3739 LEFT JOIN cc_incoterm i on i.id = r.incoterm_id
3740 LEFT JOIN cc_temperaturerange tr on tr.id = r.temperaturerange_id
3741 LEFT JOIN cc_unlocode po ON po.id = r.portorigin_id
3742 LEFT JOIN cc_unlocodelang pol ON pol.unlocode_id = po.id and pol.language_id = lang.id
3743 LEFT JOIN cc_unlocode pd ON pd.id = r.portdestination_id
3744 LEFT JOIN cc_unlocodelang pdl ON pdl.unlocode_id = pd.id and pdl.language_id = lang.id
3745 LEFT JOIN cc_airport ao ON ao.id = r.airportorigin_id
3746 LEFT JOIN cc_airport ad ON ad.id = r.airportdestination_id
3747 LEFT JOIN cc_unlocode lo ON lo.id = r.landorigin_id
3748 LEFT JOIN cc_unlocode ld ON ld.id = r.landdestination_id;
3749
3750
3751
3752
3753-- SHIPMENT TRAFFIC SEA;
3754-- ##############################################################################################
3755CREATE OR REPLACE VIEW cc_shipmenttrafficmar AS
3756 SELECT f.delegation_id,
3757 lang.id as language_id,
3758 f.isactive,
3759 shp.istrackingmark,
3760 shp.id,
3761 ft.id AS filetraffic_id,
3762 ft.file_id,
3763 ft.transportmode,
3764 ft.trafficflow,
3765 ves.name AS vesselname,
3766 ft.origin_id,
3767 ft.destination_id,
3768 ft.shippingline_id,
3769 ft.shipagent_id,
3770 ft.correspondent_id,
3771 COALESCE(pcr.name_short, pcr.name) AS correspondentname,
3772 ft.warehouse_id,
3773 ft.consolidator_id,
3774 shp.name || CASE WHEN shp.namealternate IS NOT NULL THEN '(' || shp.namealternate || ')' ELSE '' END AS name,
3775 f.name as filename,
3776 ss.containersnumber AS numcont,
3777 ft.trafficchargetype,
3778 ft.etd,
3779 ft.eta,
3780 COALESCE(oril.name, ori.name) AS origin,
3781 COALESCE(desl.name, des.name) AS destination,
3782 f.status,
3783 f.risponsable_id,
3784 f.docrisponsable_id,
3785 shp.customer_id,
3786 COALESCE(pa.name, COALESCE(p.name_short, p.name)) AS customername,
3787 shp.customerref,
3788 shp.finalclient_id,
3789 shp.documentarystatus_id,
3790 dl.name as documentarystatusname,
3791 CASE WHEN ft.trafficchargetype = 'LCL' THEN fts.containerplate ELSE ss.containerplate END AS containerplate,
3792 ss.isdangerousgoods,
3793 ss.istemperaturecontrol,
3794 ss.ispendingtask,
3795 ft.portcall,
3796 ft.bookingnumber,
3797 ft.blnumber,
3798 ft.direct,
3799 fs2.isrisk,
3800 fs2.isincident,
3801 ss.statusinvpurchase,
3802 ss.statusinvsale,
3803 ft.placereceipt_id,
3804 ft.placedelivery_id,
3805 ft.voyagenumber,
3806 ft.vessel_id,
3807 shp.salesrepresentative_id,
3808 sht.shipper_id,
3809 sht.consignee_id,
3810 sht.lettercredit,
3811 sht.lettercreditnumber,
3812 sht.customsbroker_id,
3813 sht.incoterm_id,
3814 sht.goodsinsured,
3815 ss.sadreference,
3816 ss.customsstatus,
3817 sht.correspondentref,
3818 sht.routingorder,
3819 sht.blnumber as housebl,
3820 ss.packages,
3821 ss.grossweight,
3822 ss.volume,
3823 COALESCE(pw.name_short, pw.name) as warehousename,
3824 COALESCE(pr.name_short, pr.name) as salesrepresentativename,
3825 COALESCE(ps.name_short, ps.name) as shippername,
3826 COALESCE(pc.name_short, pc.name) as consigneename,
3827 COALESCE(pb.name_short, pb.name) as customsbrokername,
3828 COALESCE(sl.name_short, sl.name) as shippinglinename,
3829 COALESCE(poag.name_short, poag.name) as originagentname,
3830 COALESCE(pdag.name_short, pdag.name) as destinationagentname,
3831 inc.code as incotermcode,
3832 pru.name as placereceiptname,
3833 pdu.name as placedeliveryname,
3834 ss.isdocumentbooking,
3835 ss.isdocumentcustomsorder,
3836 ss.isdocumenthousebl,
3837 ss.isdocumentshippinginstructions,
3838 ss.isdocumenttransportcontainer,
3839 ss.isdocumenttransportgoods,
3840 ss.isdocumentarrivalpreadvise,
3841 ss.isdocumentarrivaladvise,
3842 fts.isdocumentshippingmanifest,
3843 ss.issenttoexternalsgd,
3844
3845 ori.country_id as origincountry_id, COALESCE(clo.name, co.name) as origincountryname,
3846 des.country_id as destinationcountry_id, COALESCE(cld.name, cd.name) as destinationcountryname
3847 , u1.name as risponsablename, u2.name as docrisponsablename, ft.origincorrespondent_id
3848, sht.isgdp, f.grmsyncstatus, f.isfile,
3849 pgd.partygroup_id,
3850 CASE WHEN (SELECT count(*) AS count FROM cc_shipmentdocument sd
3851 WHERE sd.shipment_id = shp.id and sd.documenttype = 'CONFIRMATION_ONBOARD') = 1
3852 THEN 'Y' ELSE 'N'
3853 END AS isdocumentconfirmation_onboard
3854
3855 ,fts.iscontainerblanket, fts.iscontainerflexi, ft.freightcontrolled
3856
3857 FROM cc_shipment shp
3858 LEFT JOIN cc_language lang on lang.isactive = 'Y'
3859 LEFT JOIN cc_shipmenttraffic sht ON sht.shipment_id = shp.id
3860 LEFT JOIN cc_file f ON f.id = shp.file_id
3861 LEFT JOIN cc_filesummary fs2 ON fs2.file_id = f.id
3862 LEFT JOIN cc_filetraffic ft ON ft.file_id = f.id
3863 LEFT JOIN cc_filetrafficsummary fts on fts.filetraffic_id = ft.id
3864 LEFT JOIN cc_shipmentsummary ss ON ss.shipment_id = shp.id
3865 LEFT JOIN cc_unlocode ori ON ori.id = ft.origin_id
3866 LEFT JOIN cc_unlocodelang oril ON oril.unlocode_id = ori.id and oril.language_id = lang.id
3867 LEFT JOIN cc_unlocode des ON des.id = ft.destination_id
3868 LEFT JOIN cc_unlocodelang desl ON desl.unlocode_id = des.id and desl.language_id = lang.id
3869 LEFT JOIN cc_vessel ves ON ves.id = ft.vessel_id
3870 LEFT JOIN cc_partyaddress pa ON pa.id = shp.customer_id
3871 LEFT JOIN cc_party p ON p.id = pa.party_id
3872 LEFT JOIN cc_partyaddress paw on paw.id = ft.warehouse_id
3873 LEFT JOIN cc_party pw on pw.id = paw.party_id
3874 LEFT JOIN cc_partyaddress par on par.id = shp.salesrepresentative_id
3875 LEFT JOIN cc_party pr on pr.id = par.party_id
3876 LEFT JOIN cc_partyaddress pas on pas.id = sht.shipper_id
3877 LEFT JOIN cc_party ps on ps.id = pas.party_id
3878 LEFT JOIN cc_partyaddress pac on pac.id = sht.consignee_id
3879 LEFT JOIN cc_party pc on pc.id = pac.party_id
3880 LEFT JOIN cc_partyaddress pab on pab.id = sht.customsbroker_id
3881 LEFT JOIN cc_party pb on pb.id = pab.party_id
3882 LEFT JOIN cc_partyaddress pacr on pacr.id = ft.correspondent_id
3883 LEFT JOIN cc_party pcr on pcr.id = pacr.party_id
3884 LEFT JOIN cc_incoterm inc on inc.id = sht.incoterm_id
3885 LEFT JOIN cc_unlocode pru on pru.id = ft.placereceipt_id
3886 LEFT JOIN cc_unlocode pdu on pdu.id = ft.placedelivery_id
3887
3888 LEFT JOIN cc_partyaddress padag on padag.id = ft.correspondent_id
3889 LEFT JOIN cc_party pdag on pdag.id = padag.party_id
3890
3891 LEFT JOIN cc_partyaddress paoag on paoag.id = ft.origincorrespondent_id
3892 LEFT JOIN cc_party poag on poag.id = paoag.party_id
3893
3894 LEFT JOIN cc_party sl ON sl.id = ft.shippingline_id
3895
3896 LEFT JOIN cc_countrylang clo on clo.country_id = ori.country_id and clo.language_id = lang.id
3897 LEFT JOIN cc_country co on co.id = ori.country_id
3898
3899 LEFT JOIN cc_countrylang cld on cld.country_id = des.country_id and cld.language_id = lang.id
3900 LEFT JOIN cc_country cd on cd.id = des.country_id
3901
3902 LEFT JOIN cc_documentarystatuslang dl on dl.documentarystatus_id = shp.documentarystatus_id and lang.id = dl.language_id
3903
3904 LEFT JOIN cc_useraccess u1 on u1.id = f.risponsable_id
3905 LEFT JOIN cc_useraccess u2 on u2.id = f.docrisponsable_id
3906
3907 LEFT JOIN cc_partygroupdetail pgd on pgd.partyaddress_id = shp.customer_id
3908
3909 WHERE ft.transportmode::text = 'SEA'::text;
3910
3911
3912-- SHIPMENT TRAFFIC AIR;
3913-- ##############################################################################################
3914CREATE OR REPLACE VIEW cc_shipmenttrafficair AS
3915 SELECT f.delegation_id,
3916 lang.id as language_id,
3917 shp.isactive,
3918 shp.id,
3919 shp.istrackingmark,
3920 shp.file_id,
3921 ft.id as filetraffic_id,
3922 ft.transportmode,
3923 ft.trafficflow,
3924 ft.flightnumber,
3925 ft.airportorigin_id,
3926 ft.airportdestination_id,
3927 ft.airline_id,
3928 ft.correspondent_id,
3929 shp.name || CASE WHEN shp.namealternate IS NOT NULL THEN '(' || shp.namealternate || ')' ELSE '' END AS name,
3930 f.name as filename,
3931 ft.awbtype,
3932 ft.etd,
3933 ft.eta,
3934 aor.code AS origincode,
3935 aor.name AS originname,
3936 ades.code AS destinationcode,
3937 ades.name AS destinationname,
3938 f.status,
3939 f.risponsable_id,
3940 ft.blnumber,
3941 CASE
3942 WHEN ft.istransferred = 'Y'::bpchar THEN COALESCE(ffpa.name, COALESCE(ffp.name_short, ffp.name))
3943 ELSE COALESCE(alp.name_short, alp.name)
3944 END AS airlinename,
3945 ali.iatacode,
3946 shp.customer_id,
3947 COALESCE(pa.name, COALESCE(p.name_short, p.name)) AS customername,
3948 shp.customerref,
3949 shp.finalclient_id,
3950 shp.documentarystatus_id,
3951 dl.name as documentarystatusname,
3952 ss.isdangerousgoods,
3953 ss.istemperaturecontrol,
3954 ss.ispendingtask,
3955 ss.statusinvpurchase,
3956 ss.statusinvsale,
3957 fs2.isrisk,
3958 fs2.isincident,
3959 ali.trackandtraceurl,
3960
3961 shp.salesrepresentative_id,
3962 sht.shipper_id,
3963 sht.consignee_id,
3964 sht.lettercredit,
3965 sht.lettercreditnumber,
3966 sht.customsbroker_id,
3967 sht.incoterm_id,
3968 sht.goodsinsured,
3969 ss.sadreference,
3970 ss.customsstatus,
3971 sht.correspondentref,
3972 sht.routingorder,
3973
3974 sht.blnumber as housebl,
3975 ss.packages,
3976 ss.grossweight,
3977 ss.volume,
3978 COALESCE(pr.name_short, pr.name) as salesrepresentativename,
3979 COALESCE(ps.name_short, ps.name) as shippername,
3980 COALESCE(pc.name_short, pc.name) as consigneename,
3981 COALESCE(pb.name_short, pb.name) as customsbrokername,
3982 inc.code as incotermcode
3983 , ft.warehouse_id
3984 ,COALESCE(pw.name_short, pw.name) as warehousename
3985 , ft.handlingagent_id
3986 ,COALESCE(ph.name_short, ph.name) as handlingagentname,
3987
3988ss.isdocumentcustomsorder,
3989ss.isdocumentarrivalpreadvise,
3990ss.isdocumentarrivaladvise,
3991ss.isdocumenttransportgoods,
3992
3993ss.isdocumentmawb,
3994ss.isdocumenthawb,
3995ss.isdocumentlabels,
3996ss.isdocumentaircargomanifest,
3997ss.issenttoexternalsgd,
3998f.docrisponsable_id,
3999
4000
4001aor.country_id as origincountry_id, COALESCE(clo.name, co.name) as origincountryname,
4002 ades.country_id as destinationcountry_id, COALESCE(cld.name, cd.name) as destinationcountryname
4003 , u1.name as risponsablename, u2.name as docrisponsablename, ft.origincorrespondent_id, sht.isgdp
4004, f.grmsyncstatus, f.isfile, ft.cargoimpstatus, pgd.partygroup_id,
4005CASE WHEN (SELECT count(*) AS count FROM cc_shipmentdocument sd
4006 WHERE sd.shipment_id = shp.id and sd.documenttype = 'CONFIRMATION_ONBOARD') = 1
4007 THEN 'Y' ELSE 'N'
4008 END AS isdocumentconfirmation_onboard
4009
4010 FROM cc_shipment shp
4011 LEFT JOIN cc_language lang on lang.isactive = 'Y'
4012 LEFT JOIN cc_shipmenttraffic sht ON sht.shipment_id = shp.id
4013 LEFT JOIN cc_shipmentsummary ss ON ss.shipment_id = shp.id
4014 LEFT JOIN cc_file f on f.id = shp.file_id
4015 LEFT JOIN cc_filetraffic ft ON ft.file_id = f.id
4016 LEFT JOIN cc_filesummary fs2 ON fs2.file_id = f.id
4017 LEFT JOIN cc_airport aor ON aor.id = ft.airportorigin_id
4018 LEFT JOIN cc_airport ades ON ades.id = ft.airportdestination_id
4019 LEFT JOIN cc_airline ali ON ali.id = ft.airline_id
4020 LEFT JOIN cc_party alp ON alp.id = ali.party_id
4021 LEFT JOIN cc_partyaddress ffpa ON ffpa.id = ft.freightforwarder_id
4022 LEFT JOIN cc_party ffp ON ffp.id = ffpa.party_id
4023 LEFT JOIN cc_partyaddress pa ON pa.id = shp.customer_id
4024 LEFT JOIN cc_party p ON p.id = pa.party_id
4025 LEFT JOIN cc_partyaddress par on par.id = shp.salesrepresentative_id
4026 LEFT JOIN cc_party pr on pr.id = par.party_id
4027 LEFT JOIN cc_partyaddress pas on pas.id = sht.shipper_id
4028 LEFT JOIN cc_party ps on ps.id = pas.party_id
4029 LEFT JOIN cc_partyaddress pac on pac.id = sht.consignee_id
4030 LEFT JOIN cc_party pc on pc.id = pac.party_id
4031 LEFT JOIN cc_partyaddress pab on pab.id = sht.customsbroker_id
4032 LEFT JOIN cc_party pb on pb.id = pab.party_id
4033 LEFT JOIN cc_partyaddress paw on paw.id = ft.warehouse_id
4034 LEFT JOIN cc_party pw on pw.id = paw.party_id
4035
4036 LEFT JOIN cc_partyaddress pah on pah.id = ft.handlingagent_id
4037 LEFT JOIN cc_party ph on ph.id = pah.party_id
4038
4039 LEFT JOIN cc_incoterm inc on inc.id = sht.incoterm_id
4040 LEFT JOIN cc_documentarystatuslang dl on dl.documentarystatus_id = shp.documentarystatus_id and dl.language_id = lang.id
4041
4042 LEFT JOIN cc_partyaddress padag on padag.id = ft.correspondent_id
4043 LEFT JOIN cc_party pdag on pdag.id = padag.party_id
4044
4045 LEFT JOIN cc_partyaddress paoag on paoag.id = ft.origincorrespondent_id
4046 LEFT JOIN cc_party poag on poag.id = paoag.party_id
4047 LEFT JOIN cc_countrylang clo on clo.country_id = aor.country_id and clo.language_id = lang.id
4048 LEFT JOIN cc_country co on co.id = aor.country_id
4049
4050 LEFT JOIN cc_countrylang cld on cld.country_id = ades.country_id and cld.language_id = lang.id
4051 LEFT JOIN cc_country cd on cd.id = ades.country_id
4052
4053 LEFT JOIN cc_useraccess u1 on u1.id = f.risponsable_id
4054 LEFT JOIN cc_useraccess u2 on u2.id = f.docrisponsable_id
4055 LEFT JOIN cc_partygroupdetail pgd on pgd.partyaddress_id = shp.customer_id
4056
4057 WHERE ft.transportmode::text = 'AIR'::text;
4058
4059-- SHIPMENT TRAFFIC LAND;
4060-- ##############################################################################################
4061CREATE OR REPLACE VIEW cc_shipmenttrafficland AS
4062 SELECT f.delegation_id,
4063 shp.isactive,
4064 shp.id,
4065 shp.istrackingmark,
4066 ft.id as filetraffic_id,
4067 f.id AS file_id,
4068 shp.name || CASE WHEN shp.namealternate IS NOT NULL THEN '(' || shp.namealternate || ')' ELSE '' END AS name,
4069 f.name as filename,
4070 ft.trafficflow,
4071 ft.transportmode,
4072 ft.trafficchargetype,
4073 ft.eta,
4074 ft.etd,
4075 ft.inlandcarrier_id,
4076 COALESCE(pa.name, COALESCE(p.name_short, p.name)) AS inlandcarriername,
4077 ft.origin_id,
4078 COALESCE(uorl.name, uor.name) AS originname,
4079 ft.destination_id,
4080 COALESCE(udel.name, ude.name) AS destinationname,
4081 ft.blnumber,
4082 shp.customer_id,
4083 COALESCE(pca.name, COALESCE(pc.name_short, pc.name)) AS customername,
4084 shp.customerref,
4085 sht.correspondentref,
4086 shp.finalclient_id,
4087 f.status,
4088 lan.id AS language_id,
4089 ss.isdangerousgoods,
4090 ss.istemperaturecontrol,
4091 ss.ispendingtask,
4092 ss.statusinvpurchase,
4093 ss.statusinvsale,
4094 ss.issenttoexternalsgd,
4095 fs2.isrisk,
4096 fs2.isincident,
4097 shp.documentarystatus_id,
4098 dl.name as documentarystatusname
4099
4100 ,uor.country_id as origincountry_id, COALESCE(clo.name, co.name) as origincountryname,
4101 ude.country_id as destinationcountry_id, COALESCE(cld.name, cd.name) as destinationcountryname
4102 , u1.name as risponsablename, u2.name as docrisponsablename, ft.origincorrespondent_id,
4103 COALESCE(poag.name_short, poag.name) as originagentname,
4104 COALESCE(pdag.name_short, pdag.name) as destinationagentname, f.risponsable_id, ft.correspondent_id, f.docrisponsable_id
4105 , ss.sadreference, ss.customsstatus, sht.isgdp
4106, f.grmsyncstatus, f.isfile, sht.goodsinsured, pgd.partygroup_id
4107 FROM cc_shipment shp
4108 LEFT JOIN cc_shipmenttraffic sht on sht.shipment_id = shp.id
4109 LEFT JOIN cc_shipmentsummary ss ON ss.shipment_id = shp.id
4110 LEFT JOIN cc_file f ON f.id = shp.file_id
4111 LEFT JOIN cc_filetraffic ft ON ft.file_id = f.id
4112 LEFT JOIN cc_filesummary fs2 ON fs2.file_id = ft.file_id
4113 LEFT JOIN cc_partyaddress pa ON pa.id = ft.inlandcarrier_id
4114 LEFT JOIN cc_party p ON p.id = pa.party_id
4115 LEFT JOIN cc_partyaddress pca ON pca.id = shp.customer_id
4116 LEFT JOIN cc_party pc ON pc.id = pca.party_id
4117 LEFT JOIN cc_language lan ON lan.isactive = 'Y'::bpchar
4118 LEFT JOIN cc_unlocodelang uorl ON uorl.unlocode_id = ft.origin_id AND uorl.language_id = lan.id
4119 LEFT JOIN cc_unlocode uor ON uor.id = ft.origin_id
4120 LEFT JOIN cc_unlocodelang udel ON udel.unlocode_id = ft.destination_id AND udel.language_id = lan.id
4121 LEFT JOIN cc_unlocode ude ON ude.id = ft.destination_id
4122 LEFT JOIN cc_documentarystatuslang dl on dl.documentarystatus_id = shp.documentarystatus_id and dl.language_id = lan.id
4123
4124 LEFT JOIN cc_partyaddress padag on padag.id = ft.correspondent_id
4125 LEFT JOIN cc_party pdag on pdag.id = padag.party_id
4126
4127 LEFT JOIN cc_partyaddress paoag on paoag.id = ft.origincorrespondent_id
4128 LEFT JOIN cc_party poag on poag.id = paoag.party_id
4129
4130 LEFT JOIN cc_countrylang clo on clo.country_id = uor.country_id and clo.language_id = lan.id
4131 LEFT JOIN cc_country co on co.id = uor.country_id
4132
4133 LEFT JOIN cc_countrylang cld on cld.country_id = ude.country_id and cld.language_id = lan.id
4134 LEFT JOIN cc_country cd on cd.id = ude.country_id
4135
4136 LEFT JOIN cc_useraccess u1 on u1.id = f.risponsable_id
4137 LEFT JOIN cc_useraccess u2 on u2.id = f.docrisponsable_id
4138 LEFT JOIN cc_partygroupdetail pgd on pgd.partyaddress_id = shp.customer_id
4139 WHERE ft.transportmode::text = 'LAND'::text;
4140
4141-- SHIPMENT TRAFFIC COURIER;
4142-- ##############################################################################################
4143CREATE OR REPLACE VIEW cc_shipmenttrafficcour AS
4144 SELECT f.delegation_id,
4145 shp.isactive,
4146 shp.istrackingmark,
4147 shp.id,
4148 ft.id as filetraffic_id,
4149 f.id AS file_id,
4150 shp.name || CASE WHEN shp.namealternate IS NOT NULL THEN '(' || shp.namealternate || ')' ELSE '' END AS name,
4151 ft.trafficflow,
4152 ft.transportmode,
4153 ft.eta,
4154 ft.etd,
4155 ft.courieragent_id,
4156 COALESCE(pa.name, COALESCE(p.name_short, p.name)) AS courieragentname,
4157 ft.countryorigin_id,
4158 COALESCE(corl.name, cor.name) AS countryoriginname,
4159 ft.countrydestination_id,
4160 COALESCE(cdel.name, cde.name) AS countrydestinationname,
4161 ft.blnumber,
4162 ft.domesticshippingnumber,
4163 shp.customer_id,
4164 COALESCE(pca.name, COALESCE(pc.name_short, pc.name)) AS customername,
4165 shp.customerref,
4166 shp.finalclient_id,
4167 f.status,
4168 lan.id AS language_id,
4169 ss.isdangerousgoods,
4170 ss.istemperaturecontrol,
4171 ss.ispendingtask,
4172 ss.statusinvpurchase,
4173 ss.statusinvsale,
4174 ss.issenttoexternalsgd,
4175 fs2.isrisk,
4176 fs2.isincident,
4177 shp.documentarystatus_id,
4178 dl.name as documentarystatusname
4179 ,sht.correspondentref
4180
4181 ,f.risponsable_id,
4182 f.docrisponsable_id
4183 , u1.name as risponsablename, u2.name as docrisponsablename, sht.isgdp, f.grmsyncstatus, f.isfile, sht.goodsinsured,
4184 pgd.partygroup_id
4185 FROM cc_shipment shp
4186 LEFT JOIN cc_shipmenttraffic sht on sht.shipment_id = shp.id
4187 LEFT JOIN cc_shipmentsummary ss ON ss.shipment_id = shp.id
4188 LEFT JOIN cc_file f ON f.id = shp.file_id
4189 LEFT JOIN cc_filetraffic ft on ft.file_id = f.id
4190 LEFT JOIN cc_filesummary fs2 ON fs2.file_id = ft.file_id
4191 LEFT JOIN cc_partyaddress pa ON pa.id = ft.courieragent_id
4192 LEFT JOIN cc_party p ON p.id = pa.party_id
4193 LEFT JOIN cc_partyaddress pca ON pca.id = shp.customer_id
4194 LEFT JOIN cc_party pc ON pc.id = pca.party_id
4195 LEFT JOIN cc_language lan ON lan.isactive = 'Y'::bpchar
4196 LEFT JOIN cc_countrylang corl ON corl.country_id = ft.countryorigin_id AND corl.language_id = lan.id
4197 LEFT JOIN cc_country cor ON cor.id = ft.countryorigin_id
4198 LEFT JOIN cc_countrylang cdel ON cdel.country_id = ft.countrydestination_id AND cdel.language_id = lan.id
4199 LEFT JOIN cc_country cde ON cde.id = ft.countrydestination_id
4200 LEFT JOIN cc_documentarystatuslang dl on dl.documentarystatus_id = shp.documentarystatus_id and dl.language_id = lan.id
4201 LEFT JOIN cc_useraccess u1 on u1.id = f.risponsable_id
4202 LEFT JOIN cc_useraccess u2 on u2.id = f.docrisponsable_id
4203 LEFT JOIN cc_partygroupdetail pgd on pgd.partyaddress_id = shp.customer_id
4204 WHERE ft.transportmode::text = 'COUR'::text;
4205
4206-- MASTER VIEW;
4207-- ##############################################################################################
4208CREATE OR REPLACE VIEW cc_masterview AS
4209 select f.delegation_id, f.id as file_id, f.name as filename, ftr.transportmode, ftr.trafficflow, ftr.id as
4210 filetraffic_id, ftr.blnumber as masterbl, f.status as statusFile
4211 FROM cc_file f
4212 LEFT JOIN cc_filetraffic ftr on ftr.file_id = f.id
4213 WHERE ftr.blnumber IS NOT NULL and length(trim(ftr.blnumber)) > 0;
4214
4215-- HOUSE VIEW;
4216-- ##############################################################################################
4217CREATE OR REPLACE VIEW cc_houseview AS
4218 select f.delegation_id, shp.id as shipment_id, f.id as file_id, shp.name as shipmentname, ftr.transportmode, ftr
4219 .trafficflow, ftr.id as filetraffic_id, sht.blnumber as housebl, f.status as statusFile
4220 FROM cc_shipment shp
4221 LEFT JOIN cc_shipmenttraffic sht on sht.shipment_id = shp.id
4222 LEFT JOIN cc_file f on f.id = shp.file_id
4223 LEFT JOIN cc_filetraffic ftr on ftr.file_id = f.id
4224 WHERE sht.blnumber IS NOT NULL and length(trim(sht.blnumber)) > 0;
4225
4226
4227-- ACCOUNTING PROCESSES;
4228-- ##############################################################################################
4229CREATE OR REPLACE VIEW cc_accountingprocessview AS
4230 SELECT p.id,
4231 p.delegation_id,
4232 p.processdate,
4233 p.processheader_id,
4234 p.esoftcontafilename,
4235 p.status,
4236 ( SELECT count(*) AS count
4237 FROM cc_purchaseinvoiceheader
4238 WHERE cc_purchaseinvoiceheader.accountingprocess_id = p.id) AS numpurchaseinvoices,
4239 ( SELECT count(*) AS count
4240 FROM cc_saleinvoiceheader
4241 WHERE cc_saleinvoiceheader.accountingprocess_id = p.id) AS numsaleinvoices,
4242 p.esoftcontabatchnumber
4243 FROM cc_accountingprocess p;
4244
4245-- TRANSPORT ROUTE ASSESSMENT;
4246-- ##############################################################################################
4247CREATE OR REPLACE VIEW cc_transportrouteassessmentview AS
4248 select a.delegation_id, a.id, a.stage, a.topoints, a.icon, a.styleclass, l.name as result, l.language_id, lang.name as languagename
4249 FROM cc_transportrouteassessment a
4250 LEFT JOIN cc_transportrouteassessmentlang l on l.transportrouteassessment_id = a.id
4251 LEFT JOIN cc_language lang on lang.id = l.language_id;
4252
4253-- TRANSPORT ROUTE ASSESSMENT GROUP;
4254-- ##############################################################################################
4255CREATE OR REPLACE VIEW cc_transportrouteassessmentgroupview AS
4256 select ag.id, ag.delegation_id, ag.stage, agl.language_id, l.name as languagename, agl.name
4257 from cc_transportrouteassessmentgroup ag
4258 LEFT JOIN cc_transportrouteassessmentgrouplang agl on agl.transportrouteassessmentgroup_id = ag.id
4259 LEFT JOIN cc_language l on l.id = agl.language_id;
4260
4261-- TRANSPORT ROUTE ASSESSMENT ANSWER;
4262-- ##############################################################################################
4263CREATE OR REPLACE VIEW cc_transportrouteassessmentanswerview AS
4264 select aa.id, al.language_id, l.name as languagename, al.answer, aa.points, gl.name as question, aa.transportrouteassessmentgroup_id, g.stage, g.delegation_id
4265 from cc_transportrouteassessmentanswer aa
4266 LEFT JOIN cc_transportrouteassessmentanswerlang al on al.transportrouteassessmentanswer_id = aa.id
4267 LEFT JOIN cc_language l on l.id = al.language_id
4268 LEFT JOIN cc_transportrouteassessmentgrouplang gl on gl.transportrouteassessmentgroup_id = aa.transportrouteassessmentgroup_id and gl.language_id = al.language_id
4269 LEFT JOIN cc_transportrouteassessmentgroup g on g.id = aa.transportrouteassessmentgroup_id ;
4270
4271-- TRANSPORT ROUTE EVALUATION REPORT VIEW;
4272-- ##############################################################################################
4273CREATE OR REPLACE VIEW cc_transportrouteevaluationview as
4274 select tr.delegation_id, tr.id, lang.id as language_id, tr.transportmode, tr.trafficflow, 'PICKUP' as phase, 1 AS
4275 phasesort, tr.description
4276, COALESCE(dao.city, COALESCE(dao.province, COALESCE(dao.countryname, daoc.name))) as origin
4277, COALESCE(dad.city, COALESCE(dad.province, COALESCE(dad.countryname, dadc.name))) as destination
4278, tr.customer_id
4279, COALESCE(p.name_short, p.name) as customername
4280, tr.incoterm_id
4281, inc.code as incotermcode, tr.pickupnumberofvehicles as scales
4282, CASE WHEN temp.id IS NOT NULL THEN to_char(temp.tempmin, '999.99') || '-' || to_char(temp.tempmax, '999.99') || ' ' || temp.temperatureunit
4283 WHEN tr.fixedTemperature IS NOT NULL AND tr.fixedTemperature = 'Y' THEN to_char(temp.tempmax, '999.99') || ' ' || tr.temperatureunit
4284 ELSE '' END as tempcontrol
4285, COALESCE((SELECT asl.name
4286 FROM cc_transportrouteassessment tras
4287 LEFT JOIN cc_transportrouteassessmentlang asl ON asl.transportrouteassessment_id = tras.id AND asl.language_id = lang.id
4288 WHERE tras.stage = 'PICKUP' and tras.topoints >= tr.evaluationpickuppoints LIMIT 1), (SELECT asl.name
4289 FROM cc_transportrouteassessment tras
4290 LEFT JOIN cc_transportrouteassessmentlang asl ON asl.transportrouteassessment_id = tras.id AND asl.language_id = lang.id
4291 WHERE tras.stage = 'PICKUP' ORDER BY topoints DESC LIMIT 1)) AS assessmentname
4292, tr.pickupcomments
4293
4294
4295 FROM cc_transportroute tr
4296 LEFT JOIN cc_language lang on lang.isactive = 'Y'
4297 LEFT JOIN cc_docaddress dao ON dao.id = tr.pickupdocumentaddresspickup_id
4298 LEFT JOIN cc_countrylang daoc on daoc.country_id = dao.country_id and daoc.language_id = lang.id
4299
4300 LEFT JOIN cc_docaddress dad ON dad.id = tr.pickupdocumentaddressdelivery_id
4301 LEFT JOIN cc_countrylang dadc on dadc.country_id = dad.country_id and dadc.language_id = lang.id
4302
4303 LEFT JOIN cc_partyaddress pa on pa.id = tr.customer_id
4304 LEFT JOIN cc_party p on p.id = pa.party_id
4305
4306 LEFT JOIN cc_incoterm inc on inc.id = tr.incoterm_id
4307 LEFT JOIN cc_temperaturerange temp on temp.id = tr.temperaturerange_id
4308 WHERE isprintpickup IS NOT NULL and isprintpickup = 'Y'
4309
4310 UNION
4311
4312 select tr.delegation_id, tr.id, lang.id as language_id, tr.transportmode, tr.trafficflow, 'SEA' as phase, 2 AS
4313 phasesort, tr.description
4314, COALESCE(uol.name, uo.name) as origin
4315, COALESCE(udl.name, ud.name) as destination
4316, tr.customer_id
4317, COALESCE(p.name_short, p.name) as customername
4318, tr.incoterm_id
4319, inc.code as incotermcode, tr.pickupnumberofvehicles as scales
4320, CASE WHEN temp.id IS NOT NULL THEN to_char(temp.tempmin, '999.99') || '-' || to_char(temp.tempmax, '999.99') || ' ' || temp.temperatureunit
4321 WHEN tr.fixedTemperature IS NOT NULL AND tr.fixedTemperature = 'Y' THEN to_char(temp.tempmax, '999.99') || ' ' || tr.temperatureunit
4322 ELSE '' END as tempcontrol
4323, COALESCE((SELECT asl.name
4324 FROM cc_transportrouteassessment tras
4325 LEFT JOIN cc_transportrouteassessmentlang asl ON asl.transportrouteassessment_id = tras.id AND asl.language_id = lang.id
4326 WHERE tras.stage = 'MAINSEA' and tras.topoints >= tr.evaluationseapoints LIMIT 1), (SELECT asl.name
4327 FROM cc_transportrouteassessment tras
4328 LEFT JOIN cc_transportrouteassessmentlang asl ON asl.transportrouteassessment_id = tras.id AND asl.language_id = lang.id
4329 WHERE tras.stage = 'MAINSEA' ORDER BY topoints DESC LIMIT 1)) AS assessmentname
4330, tr.seacomments
4331
4332
4333 FROM cc_transportroute tr
4334 LEFT JOIN cc_language lang on lang.isactive = 'Y'
4335
4336 LEFT JOIN cc_unlocode uo on uo.id = tr.portorigin_id
4337 LEFT JOIN cc_unlocodelang uol on uol.unlocode_id = uo.id and uol.language_id = lang.id
4338
4339 LEFT JOIN cc_unlocode ud on ud.id = tr.portdestination_id
4340 LEFT JOIN cc_unlocodelang udl on udl.unlocode_id = ud.id and udl.language_id = lang.id
4341
4342 LEFT JOIN cc_partyaddress pa on pa.id = tr.customer_id
4343 LEFT JOIN cc_party p on p.id = pa.party_id
4344
4345 LEFT JOIN cc_incoterm inc on inc.id = tr.incoterm_id
4346 LEFT JOIN cc_temperaturerange temp on temp.id = tr.temperaturerange_id
4347 WHERE isprintmaintransportsea IS NOT NULL and isprintmaintransportsea = 'Y'
4348
4349 UNION
4350
4351 select tr.delegation_id, tr.id, lang.id as language_id, tr.transportmode, tr.trafficflow, 'AIR' as phase, 3 AS
4352 phasesort, tr.description
4353, aor.name as origin
4354, ade.name as destination
4355, tr.customer_id
4356, COALESCE(p.name_short, p.name) as customername
4357, tr.incoterm_id
4358, inc.code as incotermcode, tr.pickupnumberofvehicles as scales
4359, CASE WHEN temp.id IS NOT NULL THEN to_char(temp.tempmin, '999.99') || '-' || to_char(temp.tempmax, '999.99') || ' ' || temp.temperatureunit
4360 WHEN tr.fixedTemperature IS NOT NULL AND tr.fixedTemperature = 'Y' THEN to_char(temp.tempmax, '999.99') || ' ' || tr.temperatureunit
4361 ELSE '' END as tempcontrol
4362, COALESCE((SELECT asl.name
4363 FROM cc_transportrouteassessment tras
4364 LEFT JOIN cc_transportrouteassessmentlang asl ON asl.transportrouteassessment_id = tras.id AND asl.language_id = lang.id
4365 WHERE tras.stage = 'MAINAIR' and tras.topoints >= tr.evaluationairpoints LIMIT 1), (SELECT asl.name
4366 FROM cc_transportrouteassessment tras
4367 LEFT JOIN cc_transportrouteassessmentlang asl ON asl.transportrouteassessment_id = tras.id AND asl.language_id = lang.id
4368 WHERE tras.stage = 'MAINAIR' ORDER BY topoints DESC LIMIT 1)) AS assessmentname
4369, tr.aircomments
4370
4371
4372 FROM cc_transportroute tr
4373 LEFT JOIN cc_language lang on lang.isactive = 'Y'
4374
4375 LEFT JOIN cc_airport aor on aor.id = tr.airportorigin_id
4376 LEFT JOIN cc_airport ade on ade.id = tr.airportdestination_id
4377
4378 LEFT JOIN cc_partyaddress pa on pa.id = tr.customer_id
4379 LEFT JOIN cc_party p on p.id = pa.party_id
4380
4381 LEFT JOIN cc_incoterm inc on inc.id = tr.incoterm_id
4382 LEFT JOIN cc_temperaturerange temp on temp.id = tr.temperaturerange_id
4383 WHERE isprintmaintransportair IS NOT NULL and isprintmaintransportair = 'Y'
4384
4385 UNION
4386
4387 select tr.delegation_id, tr.id, lang.id as language_id, tr.transportmode, tr.trafficflow, 'LAND' as phase, 4 AS
4388 phasesort, tr.description
4389, COALESCE(dao.city, COALESCE(dao.province, COALESCE(dao.countryname, daoc.name))) as origin
4390, COALESCE(dad.city, COALESCE(dad.province, COALESCE(dad.countryname, dadc.name))) as destination
4391, tr.customer_id
4392, COALESCE(p.name_short, p.name) as customername
4393, tr.incoterm_id
4394, inc.code as incotermcode, tr.pickupnumberofvehicles as scales
4395, CASE WHEN temp.id IS NOT NULL THEN to_char(temp.tempmin, '999.99') || '-' || to_char(temp.tempmax, '999.99') || ' ' || temp.temperatureunit
4396 WHEN tr.fixedTemperature IS NOT NULL AND tr.fixedTemperature = 'Y' THEN to_char(temp.tempmax, '999.99') || ' ' || tr.temperatureunit
4397 ELSE '' END as tempcontrol
4398, COALESCE((SELECT asl.name
4399 FROM cc_transportrouteassessment tras
4400 LEFT JOIN cc_transportrouteassessmentlang asl ON asl.transportrouteassessment_id = tras.id AND asl.language_id = lang.id
4401 WHERE tras.stage = 'MAINLAND' and tras.topoints >= tr.evaluationlandpoints LIMIT 1), (SELECT asl.name
4402 FROM cc_transportrouteassessment tras
4403 LEFT JOIN cc_transportrouteassessmentlang asl ON asl.transportrouteassessment_id = tras.id AND asl.language_id = lang.id
4404 WHERE tras.stage = 'MAINLAND' ORDER BY topoints DESC LIMIT 1)) AS assessmentname
4405, tr.landcomments
4406
4407
4408 FROM cc_transportroute tr
4409 LEFT JOIN cc_language lang on lang.isactive = 'Y'
4410 LEFT JOIN cc_docaddress dao ON dao.id = tr.landdocumentaddresspickup_id
4411 LEFT JOIN cc_countrylang daoc on daoc.country_id = dao.country_id and daoc.language_id = lang.id
4412
4413 LEFT JOIN cc_docaddress dad ON dad.id = tr.landdocumentaddressdelivery_id
4414 LEFT JOIN cc_countrylang dadc on dadc.country_id = dad.country_id and dadc.language_id = lang.id
4415
4416 LEFT JOIN cc_partyaddress pa on pa.id = tr.customer_id
4417 LEFT JOIN cc_party p on p.id = pa.party_id
4418
4419 LEFT JOIN cc_incoterm inc on inc.id = tr.incoterm_id
4420 LEFT JOIN cc_temperaturerange temp on temp.id = tr.temperaturerange_id
4421 WHERE isprintmaintransportland IS NOT NULL and isprintmaintransportland = 'Y'
4422
4423
4424 UNION
4425 select tr.delegation_id, tr.id, lang.id as language_id, tr.transportmode, tr.trafficflow, 'DELIVERY' as phase, 5 AS
4426 phasesort, tr.description
4427, COALESCE(dao.city, COALESCE(dao.province, COALESCE(dao.countryname, daoc.name))) as origin
4428, COALESCE(dad.city, COALESCE(dad.province, COALESCE(dad.countryname, dadc.name))) as destination
4429, tr.customer_id
4430, COALESCE(p.name_short, p.name) as customername
4431, tr.incoterm_id
4432, inc.code as incotermcode, tr.pickupnumberofvehicles as scales
4433, CASE WHEN temp.id IS NOT NULL THEN to_char(temp.tempmin, '999.99') || '-' || to_char(temp.tempmax, '999.99') || ' ' || temp.temperatureunit
4434 WHEN tr.fixedTemperature IS NOT NULL AND tr.fixedTemperature = 'Y' THEN to_char(temp.tempmax, '999.99') || ' ' || tr.temperatureunit
4435 ELSE '' END as tempcontrol
4436, COALESCE((SELECT asl.name
4437 FROM cc_transportrouteassessment tras
4438 LEFT JOIN cc_transportrouteassessmentlang asl ON asl.transportrouteassessment_id = tras.id AND asl.language_id = lang.id
4439 WHERE tras.stage = 'DELIVERY' and tras.topoints >= tr.evaluationdeliverypoints LIMIT 1), (SELECT asl.name
4440 FROM cc_transportrouteassessment tras
4441 LEFT JOIN cc_transportrouteassessmentlang asl ON asl.transportrouteassessment_id = tras.id AND asl.language_id = lang.id
4442 WHERE tras.stage = 'DELIVERY' ORDER BY topoints DESC LIMIT 1)) AS assessmentname
4443, tr.deliverycomments
4444
4445
4446 FROM cc_transportroute tr
4447 LEFT JOIN cc_language lang on lang.isactive = 'Y'
4448 LEFT JOIN cc_docaddress dao ON dao.id = tr.deliverydocumentaddresspickup_id
4449 LEFT JOIN cc_countrylang daoc on daoc.country_id = dao.country_id and daoc.language_id = lang.id
4450
4451 LEFT JOIN cc_docaddress dad ON dad.id = tr.deliverydocumentaddressdelivery_id
4452 LEFT JOIN cc_countrylang dadc on dadc.country_id = dad.country_id and dadc.language_id = lang.id
4453
4454 LEFT JOIN cc_partyaddress pa on pa.id = tr.customer_id
4455 LEFT JOIN cc_party p on p.id = pa.party_id
4456
4457 LEFT JOIN cc_incoterm inc on inc.id = tr.incoterm_id
4458 LEFT JOIN cc_temperaturerange temp on temp.id = tr.temperaturerange_id
4459 WHERE isprintdelivery IS NOT NULL and isprintdelivery = 'Y';
4460
4461-- DOCUMENTARY STATUS;
4462-- ##############################################################################################
4463CREATE OR REPLACE VIEW cc_documentarystatusview
4464 AS SELECT d.delegation_id, d.id, d.filetype, d.transportmode, d.trafficflow, dl.language_id, dl.name, d.levelinflow
4465 FROM cc_documentarystatus d
4466 LEFT JOIN cc_documentarystatuslang dl on dl.documentarystatus_id = d.id;
4467
4468-- CUSTOMER MSOFT INTERFACE;
4469-- ##############################################################################################
4470CREATE OR REPLACE VIEW cc_customermsoftview AS
4471 SELECT p.company_id, p.id, COALESCE(p.name_short, p.name) as customername, cus.msoftcode
4472 FROM cc_customer cus
4473 LEFT JOIN cc_party p on p.id = cus.party_id;
4474
4475-- PROVIDER MSOFT INTERFACE;
4476-- ##############################################################################################
4477CREATE OR REPLACE VIEW cc_providermsoftview AS
4478 SELECT p.company_id, p.id, COALESCE(p.name_short, p.name) as providername, cus.msoftcode
4479 FROM cc_provider cus
4480 LEFT JOIN cc_party p on p.id = cus.party_id;
4481
4482-- TASK TYPES;
4483-- ##############################################################################################
4484 CREATE OR REPLACE VIEW cc_tasktypeview AS
4485 select t.id, t.delegation_id, tl.language_id, tl.name, t.iscancreatefromvisit
4486 FROM cc_tasktype t
4487 LEFT JOIN cc_tasktypelang tl on tl.tasktype_id = t.id;
4488
4489-- ##############################################################################################
4490-- TASK TYPES;
4491-- ##############################################################################################
4492CREATE OR REPLACE VIEW cc_taskview AS
4493 select t.id, t.delegation_id, tl.language_id, t.tasktype_id, tl.name as tasktype, t.assignto_id, u.name as assignedtoname, t.shipment_id, shp.name as shipmentname
4494 , t.iscompleted, t.datetask, t.datelimit, t.datecompleted, t.description, t.visit_id, t.isallday, t
4495 .customer_id, COALESCE(pa.name, COALESCE(p.name_short, p.name)) as customername
4496 FROM cc_task t
4497 LEFT JOIN cc_language l on l.isactive = 'Y'
4498 LEFT JOIN cc_tasktypelang tl on tl.language_id = l.id and tl.tasktype_id = t.tasktype_id
4499 LEFT JOIN cc_useraccess u on u.id = t.assignto_id
4500 LEFT JOIN cc_shipment shp on shp.id = t.shipment_id
4501 LEFT JOIN cc_partyaddress pa on pa.id = COALESCE(t.customer_id, shp.customer_id)
4502 LEFT JOIN cc_party p on p.id = pa.party_id;
4503
4504
4505-- VISIT TYPES;
4506-- ##############################################################################################
4507CREATE OR REPLACE VIEW cc_visittypeview AS
4508 select t.id, t.delegation_id, tl.language_id, tl.name
4509 FROM cc_visittype t
4510 LEFT JOIN cc_visittypelang tl on tl.visittype_id = t.id;
4511
4512-- VISITS;
4513-- ##############################################################################################
4514CREATE OR REPLACE VIEW cc_visitview AS
4515 select v.id, v.delegation_id, lang.id as language_id, vl.name as visittype, COALESCE(p.name_short, p.name) as customername
4516 , v.datevisit, u.name as username, v.status, v.customer_id, v.visittype_id, v.user_id, v.commentsbefore, v.isallday, v.lastinvitationsent
4517 FROM cc_visit v
4518 LEFT JOIN cc_language lang on lang.isactive = 'Y'
4519 LEFT JOIN cc_visittypelang vl on vl.language_id = lang.id and vl.visittype_id = v.visittype_id
4520 LEFT JOIN cc_partyaddress pa on pa.id = v.customer_id
4521 LEFT JOIN cc_party p on p.id = pa.party_id
4522 LEFT JOIN cc_useraccess u on u.id = v.user_id;
4523
4524-- USERS BY DELEGATION;
4525-- ##############################################################################################
4526CREATE OR REPLACE VIEW cc_userbydelegationview AS
4527 select r.delegation_id, r.user_id, u.name as username
4528 from cc_rolebyuser r
4529 LEFT JOIN cc_useraccess u ON u.id = r.user_id
4530 GROUP BY delegation_id, user_id, u.name
4531 ORDER BY delegation_id, user_id, u.name;
4532
4533-- SEA CONTRACTS;
4534-- ##############################################################################################
4535CREATE OR REPLACE VIEW cc_seacontractview AS
4536 select c.delegation_id, c.id, c.shippingline_id, COALESCE(sl.name_short, sl.name) as shippinglinename
4537 , c.contractnumber, c.trafficflow, c.freightPC, c.aprovalid, c.fromdate, c.todate
4538 , c.customer_id, COALESCE(pc.name_short, pc.name) as customername
4539
4540 FROM cc_seacontract c
4541 LEFT JOIN cc_party sl on sl.id = c.shippingline_id
4542 LEFT JOIN cc_partyaddress pac on pac.id = c.customer_id
4543 LEFT JOIN cc_party pc on pc.id = pac.party_id;
4544
4545-- TARIFF COST FREIGHT SEA;
4546-- ##############################################################################################
4547CREATE OR REPLACE VIEW cc_tariffcostfreightseaview AS
4548 select h.delegation_id, h.tariffprice_id, lang.id as language_id, h.id as id, h.shippingline_id, h.trafficflow, h.trafficchargetype, h.portorigin_id, h.portdestination_id, h.portvia_id, h.seacontract_id, h.customer_id
4549 , price.currency_id, ser.transittime, ser.frequency_id, fl.name as frequencyname, h.allinmode
4550 , COALESCE(pv.name_short, pv.name) as shippinglinename
4551 , COALESCE(ulo.name, uo.name) as portoriginname
4552 , COALESCE(uld.name, ud.name) as portdestinationname
4553 , COALESCE(ulv.name, uv.name) as portvianame
4554 , uo.country_id as countryorigin_id, ud.country_id as countrydestination_id
4555 , COALESCE(col.name, co.name) as countryoriginname
4556 , COALESCE(cdl.name, cd.name) as countrydestinationname
4557 , sc.contractnumber, COALESCE(sc.fromdate, h.fromdate) as fromdate, COALESCE(sc.todate, h.todate) as todate
4558 , COALESCE(pc.name_short, pc.name) as customername
4559 , COALESCE(cul.name, cu.code) as currencyname, cu.code as currencycode, cu.symbol as currencysymbol, cu.decimals as currencydecimals
4560 , cont1.price1 as price1, cont1.pricemin as pricemin1, cont1.pricemax as pricemax1
4561 , cont2.price1 as price2, cont2.pricemin as pricemin2, cont2.pricemax as pricemax2
4562 , cont3.price1 as price3, cont3.pricemin as pricemin3, cont3.pricemax as pricemax3
4563 , price.price1 as pricelcl, price.pricemin as priceminlcl, price.pricemax as pricemaxlcl
4564 , CASE WHEN (SELECT count(*) from cc_tariffprice pr LEFT JOIN cc_tariffcontainertype cont ON cont.tariffprice_id = pr.id WHERE pr.id = h.tariffprice_id and cont
4565 .containertype_id IS NOT NULL AND cont.containertype_id <> del.containertypetariff1_id AND cont.containertype_id <>
4566 del.containertypetariff2_id AND cont.containertype_id <> del.containertypetariff3_id) > 0 THEN 'Y' ELSE 'N' END as isothercontainers
4567 , COALESCE(areasp.partyarea_id, COALESCE(areasc.partyarea_id, COALESCE(areadp.partyarea_id, areadc.partyarea_id))) as area_id, COALESCE(areasp.partyareaname, COALESCE(areasc.partyareaname, COALESCE(areadp.partyareaname, areadc.partyareaname))) as areaname
4568
4569 FROM cc_tariffcostfreightsea h
4570 LEFT JOIN cc_party pv on pv.id = h.shippingline_id
4571 LEFT JOIN cc_language lang on lang.isactive = 'Y'
4572 LEFT JOIN cc_shippinglineservice ser ON ser.shippingline_id = h.shippingline_id and ser.portorigin_id = h.portorigin_id and ((h.portvia_id IS NULL AND ser.portvia_id IS NULL) OR (h.portvia_id IS NOT NULL AND ser.portvia_id IS NOT NULL AND h.portvia_id = ser.portvia_id)) and ser.portdestination_id = h.portdestination_id
4573 LEFT JOIN cc_frequencylang fl on fl.frequency_id = ser.frequency_id and fl.language_id = lang.id
4574 LEFT JOIN cc_unlocode uo on uo.id = h.portorigin_id
4575 LEFT JOIN cc_unlocodelang ulo on ulo.unlocode_id = uo.id and ulo.language_id = lang.id
4576 LEFT JOIN cc_unlocode ud on ud.id = h.portdestination_id
4577 LEFT JOIN cc_unlocodelang uld on uld.unlocode_id = ud.id and uld.language_id = lang.id
4578 LEFT JOIN cc_unlocode uv on uv.id = h.portvia_id
4579 LEFT JOIN cc_unlocodelang ulv on ulv.unlocode_id = uv.id and ulv.language_id = lang.id
4580 LEFT JOIN cc_country co on co.id = uo.country_id
4581 LEFT JOIN cc_countrylang col on col.country_id = co.id and col.language_id = lang.id
4582 LEFT JOIN cc_country cd on cd.id = ud.country_id
4583 LEFT JOIN cc_countrylang cdl on cdl.country_id = cd.id and cdl.language_id = lang.id
4584 LEFT JOIN cc_seacontract sc on sc.id = h.seacontract_id
4585 LEFT JOIN cc_partyaddress pac on pac.id = h.customer_id
4586 LEFT JOIN cc_party pc on pc.id = pac.party_id
4587 LEFT JOIN cc_delegation del on del.id = h.delegation_id
4588 LEFT JOIN cc_partyaddress delpa on delpa.id = del.partyaddress_id
4589
4590 LEFT JOIN cc_tariffprice price on price.id = h.tariffprice_id
4591 LEFT JOIN cc_tariffcontainertype cont1 on cont1.tariffprice_id = price.id and cont1.containertype_id = COALESCE(del.containertypetariff1_id, 0)
4592 LEFT JOIN cc_tariffcontainertype cont2 on cont2.tariffprice_id = price.id and cont2.containertype_id = COALESCE(del.containertypetariff2_id, 0)
4593 LEFT JOIN cc_tariffcontainertype cont3 on cont3.tariffprice_id = price.id and cont3.containertype_id = COALESCE(del.containertypetariff3_id, 0)
4594 LEFT JOIN cc_currency cu on cu.id = price.currency_id
4595 LEFT JOIN cc_currencylang cul on cul.parent_id = cu.id and cul.language_id = lang.id
4596 LEFT JOIN cc_partyareadetailview areasp on areasp.party_id = pv.id and areasp.transportmode = 'SEA' and areasp.port_id = CASE WHEN h.trafficflow = 'I' THEN h.portorigin_id ELSE h.portdestination_id END AND areasp.language_id = lang.id
4597 LEFT JOIN cc_partyareadetailview areasc on areasc.party_id = pv.id and areasc.transportmode = 'SEA' and areasc.country_id = CASE WHEN h.trafficflow = 'I' THEN uo.country_id ELSE ud.country_id END AND areasc.language_id = lang.id
4598 LEFT JOIN cc_partyareadetailview areadp on areadp.party_id = delpa.party_id and areadp.transportmode = 'SEA' and areadp.port_id = CASE WHEN h.trafficflow = 'I' THEN h.portorigin_id ELSE h.portdestination_id END AND areadp.language_id = lang.id
4599 LEFT JOIN cc_partyareadetailview areadc on areadc.party_id = delpa.party_id and areadc.transportmode = 'SEA' and areadc.country_id = CASE WHEN h.trafficflow = 'I' THEN uo.country_id ELSE ud.country_id END AND areadc.language_id = lang.id;
4600
4601-- TARIFF COST FREIGHT SEA HISTO;
4602-- ##############################################################################################
4603 CREATE OR REPLACE VIEW cc_tariffcostfreightseahstview AS
4604 select h.delegation_id, h.tariffprice_id, lang.id as language_id, h.id as id, h.shippingline_id, h.trafficflow, h.trafficchargetype, h.portorigin_id, h.portdestination_id, h.portvia_id, h.seacontract_id, h.customer_id
4605 , price.currency_id, ser.transittime, ser.frequency_id, fl.name as frequencyname, h.allinmode
4606 , COALESCE(pv.name_short, pv.name) as shippinglinename
4607 , COALESCE(ulo.name, uo.name) as portoriginname
4608 , COALESCE(uld.name, ud.name) as portdestinationname
4609 , COALESCE(ulv.name, uv.name) as portvianame
4610 , uo.country_id as countryorigin_id, ud.country_id as countrydestination_id
4611 , COALESCE(col.name, co.name) as countryoriginname
4612 , COALESCE(cdl.name, cd.name) as countrydestinationname
4613 , sc.contractnumber, COALESCE(sc.fromdate, h.fromdate) as fromdate, COALESCE(sc.todate, h.todate) as todate
4614 , COALESCE(pc.name_short, pc.name) as customername
4615 , COALESCE(cul.name, cu.code) as currencyname, cu.code as currencycode, cu.symbol as currencysymbol, cu.decimals as currencydecimals
4616 , cont1.price1 as price1, cont1.pricemin as pricemin1, cont1.pricemax as pricemax1
4617 , cont2.price1 as price2, cont2.pricemin as pricemin2, cont2.pricemax as pricemax2
4618 , cont3.price1 as price3, cont3.pricemin as pricemin3, cont3.pricemax as pricemax3
4619 , price.price1 as pricelcl, price.pricemin as priceminlcl, price.pricemax as pricemaxlcl
4620 , CASE WHEN (SELECT count(*) from cc_tariffprice_hst pr LEFT JOIN cc_tariffcontainertype_hst cont ON cont.tariffprice_id = pr.id WHERE pr.id = h.tariffprice_id and cont
4621 .containertype_id IS NOT NULL AND cont.containertype_id <> del.containertypetariff1_id AND cont.containertype_id <>
4622 del.containertypetariff2_id AND cont.containertype_id <> del.containertypetariff3_id) > 0 THEN 'Y' ELSE 'N' END as isothercontainers
4623 , COALESCE(areasp.partyarea_id, COALESCE(areasc.partyarea_id, COALESCE(areadp.partyarea_id, areadc.partyarea_id))) as area_id, COALESCE(areasp.partyareaname, COALESCE(areasc.partyareaname, COALESCE(areadp.partyareaname, areadc.partyareaname))) as areaname
4624 , h.createddate
4625
4626 FROM cc_tariffcostfreightsea_hst h
4627 LEFT JOIN cc_party pv on pv.id = h.shippingline_id
4628 LEFT JOIN cc_language lang on lang.isactive = 'Y'
4629 LEFT JOIN cc_shippinglineservice ser ON ser.shippingline_id = h.shippingline_id and ser.portorigin_id = h.portorigin_id and ((h.portvia_id IS NULL AND ser.portvia_id IS NULL) OR (h.portvia_id IS NOT NULL AND ser.portvia_id IS NOT NULL AND h.portvia_id = ser.portvia_id)) and ser.portdestination_id = h.portdestination_id
4630 LEFT JOIN cc_frequencylang fl on fl.frequency_id = ser.frequency_id and fl.language_id = lang.id
4631 LEFT JOIN cc_unlocode uo on uo.id = h.portorigin_id
4632 LEFT JOIN cc_unlocodelang ulo on ulo.unlocode_id = uo.id and ulo.language_id = lang.id
4633 LEFT JOIN cc_unlocode ud on ud.id = h.portdestination_id
4634 LEFT JOIN cc_unlocodelang uld on uld.unlocode_id = ud.id and uld.language_id = lang.id
4635 LEFT JOIN cc_unlocode uv on uv.id = h.portvia_id
4636 LEFT JOIN cc_unlocodelang ulv on ulv.unlocode_id = uv.id and ulv.language_id = lang.id
4637 LEFT JOIN cc_country co on co.id = uo.country_id
4638 LEFT JOIN cc_countrylang col on col.country_id = co.id and col.language_id = lang.id
4639 LEFT JOIN cc_country cd on cd.id = ud.country_id
4640 LEFT JOIN cc_countrylang cdl on cdl.country_id = cd.id and cdl.language_id = lang.id
4641 LEFT JOIN cc_seacontract sc on sc.id = h.seacontract_id
4642 LEFT JOIN cc_partyaddress pac on pac.id = h.customer_id
4643 LEFT JOIN cc_party pc on pc.id = pac.party_id
4644 LEFT JOIN cc_delegation del on del.id = h.delegation_id
4645 LEFT JOIN cc_partyaddress delpa on delpa.id = del.partyaddress_id
4646
4647 LEFT JOIN cc_tariffprice_hst price on price.id = h.tariffprice_id
4648 LEFT JOIN cc_tariffcontainertype_hst cont1 on cont1.tariffprice_id = price.id and cont1.containertype_id = COALESCE(del.containertypetariff1_id, 0)
4649 LEFT JOIN cc_tariffcontainertype_hst cont2 on cont2.tariffprice_id = price.id and cont2.containertype_id = COALESCE(del.containertypetariff2_id, 0)
4650 LEFT JOIN cc_tariffcontainertype_hst cont3 on cont3.tariffprice_id = price.id and cont3.containertype_id = COALESCE(del.containertypetariff3_id, 0)
4651 LEFT JOIN cc_currency cu on cu.id = price.currency_id
4652 LEFT JOIN cc_currencylang cul on cul.parent_id = cu.id and cul.language_id = lang.id
4653 LEFT JOIN cc_partyareadetailview areasp on areasp.party_id = pv.id and areasp.transportmode = 'SEA' and areasp.port_id = CASE WHEN h.trafficflow = 'I' THEN h.portorigin_id ELSE h.portdestination_id END AND areasp.language_id = lang.id
4654 LEFT JOIN cc_partyareadetailview areasc on areasc.party_id = pv.id and areasc.transportmode = 'SEA' and areasc.country_id = CASE WHEN h.trafficflow = 'I' THEN uo.country_id ELSE ud.country_id END AND areasc.language_id = lang.id
4655 LEFT JOIN cc_partyareadetailview areadp on areadp.party_id = delpa.party_id and areadp.transportmode = 'SEA' and areadp.port_id = CASE WHEN h.trafficflow = 'I' THEN h.portorigin_id ELSE h.portdestination_id END AND areadp.language_id = lang.id
4656 LEFT JOIN cc_partyareadetailview areadc on areadc.party_id = delpa.party_id and areadc.transportmode = 'SEA' and areadc.country_id = CASE WHEN h.trafficflow = 'I' THEN uo.country_id ELSE ud.country_id END AND areadc.language_id = lang.id;
4657
4658
4659
4660-- FREQUENCIES;
4661-- ##############################################################################################
4662CREATE OR REPLACE VIEW cc_frequencyview AS
4663 select f.id, f.days, fl.name, fl.language_id
4664 from cc_frequency f
4665 LEFT JOIN cc_frequencylang fl on fl.frequency_id = f.id;
4666
4667-- TARIFF DICTIONARY;
4668-- ##############################################################################################
4669CREATE OR REPLACE VIEW cc_tariffdictionaryview AS
4670 SELECT d.id, d.delegation_id, lang.id as language_id, d.section, d.field, d.originaltext, d.party_id
4671 , d.unlocode1_id, d.unlocode2_id, d.unlocode3_id, d.unlocode4_id
4672 , d.frequency_id
4673 , COALESCE(p.name_short, p.name) as partyname
4674 , COALESCE(ul1.name, u1.name) as unlocodename1, COALESCE(ul2.name, u2.name) as unlocodename2, COALESCE(ul3.name, u3.name) as unlocodename3, COALESCE(ul4.name, u4.name) as unlocodename4
4675 , fl.name as frequencyname, d.shippingline_id, COALESCE(sl.name_short, sl.name) as shippinglinename
4676 , ct1.code as containertypecode1, ct1.name as containertypename1, ct2.code as containertypecode2, ct2.name as containertypename2, ct3.code as containertypecode3, ct3.name as containertypename3
4677 , COALESCE(cl.name, c.name) as countryname, d.isdirect, d.paymenttype_id, d.effectsnumber, d.effectsdays, tpl.name as paymenttypename
4678 FROM cc_tariffdictionary d
4679 LEFT JOIN cc_party p on p.id = d.party_id
4680 LEFT JOIN cc_language lang on lang.isactive = 'Y'
4681 LEFT JOIN cc_unlocodelang ul1 on ul1.unlocode_id = d.unlocode1_id and ul1.language_id = lang.id
4682 LEFT JOIN cc_unlocode u1 on u1.id = ul1.unlocode_id
4683 LEFT JOIN cc_unlocodelang ul2 on ul2.unlocode_id = d.unlocode2_id and ul2.language_id = lang.id
4684 LEFT JOIN cc_unlocode u2 on u2.id = ul2.unlocode_id
4685 LEFT JOIN cc_unlocodelang ul3 on ul3.unlocode_id = d.unlocode3_id and ul3.language_id = lang.id
4686 LEFT JOIN cc_unlocode u3 on u3.id = ul3.unlocode_id
4687 LEFT JOIN cc_unlocodelang ul4 on ul4.unlocode_id = d.unlocode4_id and ul4.language_id = lang.id
4688 LEFT JOIN cc_unlocode u4 on u4.id = ul4.unlocode_id
4689 LEFT JOIN cc_frequencylang fl on fl.id = d.frequency_id and fl.language_id = lang.id
4690 LEFT JOIN cc_party sl on sl.id = d.shippingline_id
4691 LEFT JOIN cc_containertype ct1 on ct1.id = d.containertype1_id
4692 LEFT JOIN cc_containertype ct2 on ct2.id = d.containertype2_id
4693 LEFT JOIN cc_containertype ct3 on ct3.id = d.containertype3_id
4694 LEFT JOIN cc_countrylang cl on cl.country_id = d.country_id and cl.language_id = lang.id
4695 LEFT JOIN cc_country c on c.id = d.country_id
4696 LEFT JOIN cc_paymenttypelang tpl on tpl.parent_id = d.paymenttype_id and tpl.language_id = lang.id;
4697
4698-- INVOICE CONCEPT TYPE;
4699-- ##############################################################################################
4700CREATE OR REPLACE VIEW cc_invoiceconcepttypeview AS
4701 select it.delegation_id, it.id, itl.language_id, itl.name FROM cc_invoiceconcepttype it LEFT JOIN cc_invoiceconcepttypelang itl on itl.parent_id = it.id ;
4702
4703-- TARIFF COST SEA;
4704-- ##############################################################################################
4705 CREATE OR REPLACE VIEW cc_tariffcostsurchargeseaview AS
4706 select t.id, t.delegation_id, lang.id as language_id, t.shippingline_id, t.trafficflow, t.trafficchargetype, t.localport_id, t.port_id, t.country_id, t.partyarea_id, t.seacontract_id, t.fromdate, t.todate, pr.currency_id
4707 , COALESCE(p.name_short, p.name) as shippinglinename, COALESCE(ul1.name, u1.name) as localportname, COALESCE(ul2.name, u2.name) as portname, COALESCE(cl.name, c.name) as countryname
4708 , par.name as partyareaname, sc.contractnumber, COALESCE(pc.name_short, pc.name) as customername, pr.invoiceconcept_id, COALESCE(icl.name_short, icl.name) as invoiceconceptname, pr.tariffrule, par.currency_id as partyareacurrency_id
4709 , ic.tariffcalculationmode, pr.id as tariffprice_id, pr.kgsbym3, pr.kgsbylinearmeter
4710 FROM cc_tariffprice pr
4711 LEFT JOIN cc_tariffcostsurchargesea t on t.tariffprice_id = pr.id
4712 LEFT JOIN cc_party p on p.id = t.shippingline_id
4713 LEFT JOIN cc_language lang on lang.isactive = 'Y'
4714 LEFT JOIN cc_unlocodelang ul1 on ul1.unlocode_id = t.localport_id and ul1.language_id = lang.id
4715 LEFT JOIN cc_unlocode u1 on u1.id = t.localport_id
4716 LEFT JOIN cc_unlocodelang ul2 on ul2.unlocode_id = t.port_id and ul2.language_id = lang.id
4717 LEFT JOIN cc_unlocode u2 on u2.id = t.port_id
4718 LEFT JOIN cc_countrylang cl on cl.id = t.country_id
4719 LEFT JOIN cc_country c on c.id = t.country_id
4720 LEFT JOIN cc_partyarea par on par.id = t.partyarea_id
4721 LEFT JOIN cc_seacontract sc on sc.id = t.seacontract_id
4722 LEFT JOIN cc_partyaddress pac on pac.id = sc.customer_id
4723 LEFT JOIN cc_party pc on pc.id = pac.party_id
4724 LEFT JOIN cc_invoiceconcept ic on ic.id = pr.invoiceconcept_id
4725 LEFT JOIN cc_invoiceconceptlang icl on icl.parent_id = pr.invoiceconcept_id and icl.language_id = lang.id
4726 WHERE t.id IS NOT NULL
4727 GROUP BY t.id, t.delegation_id, lang.id, t.shippingline_id, t.trafficflow, t.trafficchargetype, t.localport_id, t.port_id, t.country_id, t.partyarea_id, t.seacontract_id, t.fromdate, t.todate, pr.currency_id
4728 , COALESCE(p.name_short, p.name), COALESCE(ul1.name, u1.name), COALESCE(ul2.name, u2.name), COALESCE(cl.name, c.name)
4729 , par.name, sc.contractnumber, COALESCE(pc.name_short, pc.name), pr.invoiceconcept_id, COALESCE(icl.name_short, icl.name), pr.tariffrule, par.currency_id, ic.tariffcalculationmode, pr.id
4730 ORDER BY t.id, t.delegation_id, lang.id, t.shippingline_id, t.trafficflow, t.trafficchargetype, t.localport_id, t
4731 .port_id, t.country_id, t.partyarea_id, t.seacontract_id, t.fromdate, t.todate, pr.currency_id
4732 , COALESCE(p.name_short, p.name), COALESCE(ul1.name, u1.name), COALESCE(ul2.name, u2.name), COALESCE(cl.name, c.name)
4733 , par.name, sc.contractnumber, COALESCE(pc.name_short, pc.name), pr.invoiceconcept_id, COALESCE(icl.name_short, icl.name), pr.tariffrule, par.currency_id, ic.tariffcalculationmode, pr.id;
4734
4735
4736
4737-- TARIFF COST SEA HISTO;
4738-- ##############################################################################################
4739 CREATE OR REPLACE VIEW cc_tariffcostsurchargeseahstview AS
4740 select t.id, t.delegation_id, lang.id as language_id, t.shippingline_id, t.trafficflow, t.trafficchargetype, t.localport_id, t.port_id, t.country_id, t.partyarea_id, t.seacontract_id, t.fromdate, t.todate, pr.currency_id
4741 , COALESCE(p.name_short, p.name) as shippinglinename, COALESCE(ul1.name, u1.name) as localportname, COALESCE(ul2.name, u2.name) as portname, COALESCE(cl.name, c.name) as countryname
4742 , par.name as partyareaname, sc.contractnumber, COALESCE(pc.name_short, pc.name) as customername, pr.invoiceconcept_id, COALESCE(icl.name_short, icl.name) as invoiceconceptname, pr.tariffrule, par.currency_id as partyareacurrency_id
4743 , ic.tariffcalculationmode, pr.id as tariffprice_id, pr.kgsbym3, pr.kgsbylinearmeter
4744 FROM cc_tariffprice_hst pr
4745 LEFT JOIN cc_tariffcostsurchargesea_hst t on t.tariffprice_id = pr.id
4746 LEFT JOIN cc_party p on p.id = t.shippingline_id
4747 LEFT JOIN cc_language lang on lang.isactive = 'Y'
4748 LEFT JOIN cc_unlocodelang ul1 on ul1.unlocode_id = t.localport_id and ul1.language_id = lang.id
4749 LEFT JOIN cc_unlocode u1 on u1.id = t.localport_id
4750 LEFT JOIN cc_unlocodelang ul2 on ul2.unlocode_id = t.port_id and ul2.language_id = lang.id
4751 LEFT JOIN cc_unlocode u2 on u2.id = t.port_id
4752 LEFT JOIN cc_countrylang cl on cl.id = t.country_id
4753 LEFT JOIN cc_country c on c.id = t.country_id
4754 LEFT JOIN cc_partyarea par on par.id = t.partyarea_id
4755 LEFT JOIN cc_seacontract sc on sc.id = t.seacontract_id
4756 LEFT JOIN cc_partyaddress pac on pac.id = sc.customer_id
4757 LEFT JOIN cc_party pc on pc.id = pac.party_id
4758 LEFT JOIN cc_invoiceconcept ic on ic.id = pr.invoiceconcept_id
4759 LEFT JOIN cc_invoiceconceptlang icl on icl.parent_id = pr.invoiceconcept_id and icl.language_id = lang.id
4760 WHERE t.id IS NOT NULL
4761 GROUP BY t.id, t.delegation_id, lang.id, t.shippingline_id, t.trafficflow, t.trafficchargetype, t.localport_id, t.port_id, t.country_id, t.partyarea_id, t.seacontract_id, t.fromdate, t.todate, pr.currency_id
4762 , COALESCE(p.name_short, p.name), COALESCE(ul1.name, u1.name), COALESCE(ul2.name, u2.name), COALESCE(cl.name, c.name)
4763 , par.name, sc.contractnumber, COALESCE(pc.name_short, pc.name), pr.invoiceconcept_id, COALESCE(icl.name_short, icl.name), pr.tariffrule, par.currency_id, ic.tariffcalculationmode, pr.id
4764 ORDER BY t.id, t.delegation_id, lang.id, t.shippingline_id, t.trafficflow, t.trafficchargetype, t.localport_id, t
4765 .port_id, t.country_id, t.partyarea_id, t.seacontract_id, t.fromdate, t.todate, pr.currency_id
4766 , COALESCE(p.name_short, p.name), COALESCE(ul1.name, u1.name), COALESCE(ul2.name, u2.name), COALESCE(cl.name, c.name)
4767 , par.name, sc.contractnumber, COALESCE(pc.name_short, pc.name), pr.invoiceconcept_id, COALESCE(icl.name_short, icl.name), pr.tariffrule, par.currency_id, ic.tariffcalculationmode, pr.id;
4768
4769-- TARIFF PRICE;
4770-- ##############################################################################################
4771CREATE OR REPLACE VIEW cc_tariffpricesurchargeview AS
4772 select h.delegation_id, lang.id as language_id, p.id, prc.containertype_id, p.invoiceconcept_id
4773 , COALESCE(prc.price1, p.price1) as price1, COALESCE(prc.price2, p.price2) as price2, COALESCE(prc.percentage, p.percentage) as percentage, COALESCE(prc.pricemin, p.pricemin) as pricemin, COALESCE(prc.pricemax, p.pricemax) as pricemax, p.tariffrule
4774 , p.currency_id, cur.code as currencycode, cur.decimals as currencydecimals, cur.symbol as currencysymbols, icl.name as invoiceconceptname, ic.printorder as invoiceconceptprintorder, ict.printorder as invoiceconcepttypeprintorder
4775 , ct.code as containertypecode, COALESCE(ct.name_short, ct.name) as containertypename, p.iscurrencyfromparent, ict.classification
4776 FROM cc_tariffcostsurchargesea h
4777 LEFT JOIN cc_language lang on lang.isactive = 'Y'
4778 LEFT JOIN cc_tariffprice p on p.id = h.tariffprice_id
4779 LEFT JOIN cc_currency cur on cur.id = p.currency_id
4780 LEFT JOIN cc_invoiceconceptlang icl on icl.language_id = lang.id and icl.parent_id = p.invoiceconcept_id
4781 LEFT JOIN cc_invoiceconcept ic on ic.id = p.invoiceconcept_id
4782 LEFT JOIN cc_invoiceconcepttype ict on ict.id = ic.invoiceconcepttype_id
4783 LEFT JOIN cc_tariffcontainertype prc on prc.tariffprice_id = p.id
4784 LEFT JOIN cc_containertype ct on ct.id = prc.containertype_id;
4785
4786
4787-- TARIFF PRICE EXPENSE;
4788-- ##############################################################################################
4789CREATE OR REPLACE VIEW cc_tariffcostexpenseseaview AS
4790 SELECT h.delegation_id, h.id as id, h.party_id, h.trafficflow, h.localport_id, h.seacontract_id
4791 , h.fromdate, h.todate, h.trafficchargetype, COALESCE(ul.name, u.name) as localportname, COALESCE(ps.name_short, ps.name) as partyname
4792 , sc.customer_id, COALESCE(pc.name_short, pc.name) as customername, sc.contractnumber
4793 , lang.id as language_id, p.id as tariffprice_id, p.invoiceconcept_id, p.tariffrule
4794 , p.price1, p.price2, p.percentage, p.pricemin, p.pricemax
4795 , cont1.price1 as price11, cont1.price2 as price12, cont1.pricemin as pricemin1, cont1.pricemax as pricemax1, cont1.percentage as percentage1
4796 , cont2.price1 as price21, cont2.price2 as price22, cont2.pricemin as pricemin2, cont2.pricemax as pricemax2, cont2.percentage as percentage2
4797 , cont3.price1 as price31, cont3.price2 as price32, cont3.pricemin as pricemin3, cont3.pricemax as pricemax3, cont3.percentage as percentage3
4798 , p.currency_id, cur.code as currencycode, cur.decimals as currencydecimals, cur.symbol as currencysymbols
4799 , icl.name as invoiceconceptname, ic.printorder as invoiceconceptprintorder, ict.printorder as invoiceconcepttypeprintorder
4800 , del.containertypetariff1_id, del.containertypetariff2_id, del.containertypetariff3_id
4801
4802 FROM cc_tariffcostexpensesea h
4803 LEFT JOIN cc_tariffprice p on p.id = h.tariffprice_id
4804 LEFT JOIN cc_language lang on lang.isactive = 'Y'
4805 LEFT JOIN cc_delegation del on del.id = h.delegation_id
4806 LEFT JOIN cc_currency cur on cur.id = p.currency_id
4807 LEFT JOIN cc_invoiceconceptlang icl on icl.language_id = lang.id and icl.parent_id = p.invoiceconcept_id
4808 LEFT JOIN cc_invoiceconcept ic on ic.id = p.invoiceconcept_id
4809 LEFT JOIN cc_invoiceconcepttype ict on ict.id = ic.invoiceconcepttype_id
4810 LEFT JOIN cc_unlocodelang ul on ul.language_id = lang.id and ul.unlocode_id = h.localport_id
4811 LEFT JOIN cc_unlocode u on u.id = h.localport_id
4812 LEFT JOIN cc_party ps on ps.id = h.party_id
4813 LEFT JOIN cc_seacontract sc on sc.id = h.seacontract_id
4814 LEFT JOIN cc_partyaddress pa on pa.id = sc.customer_id
4815 LEFT JOIN cc_party pc on pc.id = pa.party_id
4816
4817 LEFT JOIN cc_tariffcontainertype cont1 on cont1.tariffprice_id = p.id and cont1.containertype_id = del.containertypetariff1_id
4818 LEFT JOIN cc_tariffcontainertype cont2 on cont2.tariffprice_id = p.id and cont2.containertype_id = del.containertypetariff2_id
4819 LEFT JOIN cc_tariffcontainertype cont3 on cont3.tariffprice_id = p.id and cont3.containertype_id = del.containertypetariff3_id;
4820
4821
4822
4823 -- TARIFF PRICE EXPENSE HISTO;
4824-- ##############################################################################################
4825CREATE OR REPLACE VIEW cc_tariffcostexpenseseahstview AS
4826 SELECT h.delegation_id, h.id as id, h.party_id, h.trafficflow, h.localport_id, h.seacontract_id
4827 , h.fromdate, h.todate, h.trafficchargetype, COALESCE(ul.name, u.name) as localportname, COALESCE(ps.name_short, ps.name) as partyname
4828 , sc.customer_id, COALESCE(pc.name_short, pc.name) as customername, sc.contractnumber
4829 , lang.id as language_id, p.id as tariffprice_id, p.invoiceconcept_id, p.tariffrule
4830 , p.price1, p.price2, p.percentage, p.pricemin, p.pricemax
4831 , cont1.price1 as price11, cont1.price2 as price12, cont1.pricemin as pricemin1, cont1.pricemax as pricemax1, cont1.percentage as percentage1
4832 , cont2.price1 as price21, cont2.price2 as price22, cont2.pricemin as pricemin2, cont2.pricemax as pricemax2, cont2.percentage as percentage2
4833 , cont3.price1 as price31, cont3.price2 as price32, cont3.pricemin as pricemin3, cont3.pricemax as pricemax3, cont3.percentage as percentage3
4834 , p.currency_id, cur.code as currencycode, cur.decimals as currencydecimals, cur.symbol as currencysymbols
4835 , icl.name as invoiceconceptname, ic.printorder as invoiceconceptprintorder, ict.printorder as invoiceconcepttypeprintorder
4836 , del.containertypetariff1_id, del.containertypetariff2_id, del.containertypetariff3_id
4837
4838 FROM cc_tariffcostexpensesea_hst h
4839 LEFT JOIN cc_tariffprice_hst p on p.id = h.tariffprice_id
4840 LEFT JOIN cc_language lang on lang.isactive = 'Y'
4841 LEFT JOIN cc_delegation del on del.id = h.delegation_id
4842 LEFT JOIN cc_currency cur on cur.id = p.currency_id
4843 LEFT JOIN cc_invoiceconceptlang icl on icl.language_id = lang.id and icl.parent_id = p.invoiceconcept_id
4844 LEFT JOIN cc_invoiceconcept ic on ic.id = p.invoiceconcept_id
4845 LEFT JOIN cc_invoiceconcepttype ict on ict.id = ic.invoiceconcepttype_id
4846 LEFT JOIN cc_unlocodelang ul on ul.language_id = lang.id and ul.unlocode_id = h.localport_id
4847 LEFT JOIN cc_unlocode u on u.id = h.localport_id
4848 LEFT JOIN cc_party ps on ps.id = h.party_id
4849 LEFT JOIN cc_seacontract sc on sc.id = h.seacontract_id
4850 LEFT JOIN cc_partyaddress pa on pa.id = sc.customer_id
4851 LEFT JOIN cc_party pc on pc.id = pa.party_id
4852
4853 LEFT JOIN cc_tariffcontainertype_hst cont1 on cont1.tariffprice_id = p.id and cont1.containertype_id = del.containertypetariff1_id
4854 LEFT JOIN cc_tariffcontainertype_hst cont2 on cont2.tariffprice_id = p.id and cont2.containertype_id = del.containertypetariff2_id
4855 LEFT JOIN cc_tariffcontainertype_hst cont3 on cont3.tariffprice_id = p.id and cont3.containertype_id = del.containertypetariff3_id;
4856
4857
4858-- COMMERCIAL OFFER;
4859-- ##############################################################################################
4860 CREATE OR REPLACE VIEW cc_commercialofferview AS
4861 SELECT
4862 h.commercialoffertype, h.name, h.filetype,
4863 h.id, h.delegation_id, lang.id as language_id, h.transportmode, h.trafficflow, h.trafficchargetype
4864, h.customsbroker_id, h.incoterm_id, h.goodsinsured, h.customer_id, h.salesrepresentative_id
4865, h.remarks, h.status, h.grossweight, h.description
4866, h.volume, h.fromdate, h.todate, h.visit_id, h.inlandcarrier_id, h.offerdate, h.isdangerousgoods, h
4867.istemperaturecontrol, h.isgdp
4868, COALESCE(pacb.name_short, pacb.name) as customsbrokername
4869, inc.code as incotermcode
4870, h.ispartygroup , h.partygroup_id
4871, CASE WHEN h.ispartygroup = 'Y' THEN pgl.name ELSE COALESCE(pacu.name_short, pacu.name) END as customername
4872, COALESCE(pai.name_short, pai.name) as inlandcarriername
4873, COALESCE(pasr.name_short, pasr.name) as salesrepresentativename
4874, h.format, h.contactname, h.packages, h.customerref, h.numberofservices
4875
4876 , h.origin_id, COALESCE(ul1.name, u1.name) as originname
4877 , h.destination_id, COALESCE(ul2.name, u2.name) as destinationname
4878 , h.airportorigin_id, h.airportdestination_id, a1.name as airportoriginname, a2.name as airportdestinationname
4879
4880 FROM cc_commercialofferheader h
4881 LEFT JOIN cc_language lang on lang.isactive = 'Y'
4882 LEFT JOIN cc_partyaddress pacba on pacba.id = h.customsbroker_id
4883 LEFT JOIN cc_party pacb on pacb.id = pacba.party_id
4884 LEFT JOIN cc_incoterm inc on inc.id = h.incoterm_id
4885 LEFT JOIN cc_partyaddress pacua on pacua.id = h.customer_id
4886 LEFT JOIN cc_party pacu on pacu.id = pacua.party_id
4887 LEFT JOIN cc_partyaddress pasra on pasra.id = h.salesrepresentative_id
4888 LEFT JOIN cc_party pasr on pasr.id = pasra.party_id
4889 LEFT JOIN cc_partyaddress paia on paia.id = h.inlandcarrier_id
4890 LEFT JOIN cc_party pai on pai.id = paia.party_id
4891 LEFT JOIN cc_partygroup pg on pg.id = h.partygroup_id
4892 LEFT JOIN cc_partygrouplang pgl on pgl.language_id = lang.id and pgl.partygroup_id = pg.id
4893
4894 LEFT JOIN cc_unlocode u1 on u1.id = h.origin_id
4895 LEFT JOIN cc_unlocodelang ul1 on ul1.unlocode_id = h.origin_id and ul1.language_id = lang.id
4896 LEFT JOIN cc_unlocode u2 on u2.id = h.destination_id
4897 LEFT JOIN cc_unlocodelang ul2 on ul2.unlocode_id = h.destination_id and ul2.language_id = lang.id
4898 LEFT JOIN cc_airport a1 on a1.id = h.airportorigin_id
4899 LEFT JOIN cc_airport a2 on a2.id = h.airportdestination_id
4900;
4901
4902-- TARIFF COST GENERAL;
4903-- ##############################################################################################
4904CREATE OR REPLACE VIEW cc_tariffcostgeneralview AS
4905 select t.id, lang.id as language_id, t.delegation_id, t.tarifftype, t.transportmode, t.trafficflow, t
4906 .trafficchargetype, t.partyaddress_id, t.customer_id, t.fromdate, t.todate, COALESCE
4907 (ppa.name, COALESCE(pp.name_short, pp.name)) as providername
4908
4909, t.localport_id, COALESCE(lul.name, lu.name) as localportname, t.localairport_id, t.port_id, t.airport_id, lair.name as localairportname, t.partyarea_id, t.country_id
4910
4911, COALESCE(ul.name, u.name) as portname, air.name as airportname, area.name as partyareaname, COALESCE(cl.name, c.name) as countryname
4912, COALESCE(cpa.name, COALESCE(cp.name_short, cp.name)) as customername
4913, p.tariffrule, pct.containertype_id
4914, COALESCE(pct.price1, p.price1) as price1, COALESCE(pct.price2, p.price2) as price2, COALESCE(pct.pricemin, p.pricemin) as pricemin, COALESCE(pct.pricemax, p.pricemax) as pricemax, COALESCE(pct.percentage, p.percentage) as percentage
4915, p.currency_id, p
4916.invoiceconcept_id
4917, icl.name as invoiceconceptname, cur.code as currencycode, cur.symbol as currencysymbol, curl.name as currencyname
4918, ct.code as containertypecode, COALESCE(ct.name_short, ct.name) as containertypename, p.id as tariffprice_id, p.kgsbym3, p.kgsbylinearmeter
4919
4920 from cc_tariffcostgeneral t
4921 LEFT JOIN cc_language lang on lang.isactive = 'Y'
4922 LEFT JOIN cc_partyaddress ppa on ppa.id = t.partyaddress_id
4923 LEFT JOIN cc_party pp on pp.id = ppa.party_id
4924
4925 LEFT JOIN cc_unlocode lu on lu.id = t.localport_id
4926 LEFT JOIN cc_unlocodelang lul on lul.language_id = lang.id and lul.unlocode_id = lu.id
4927
4928 LEFT JOIN cc_airport lair on lair.id = t.localairport_id
4929
4930 LEFT JOIN cc_unlocode u on u.id = t.port_id
4931 LEFT JOIN cc_unlocodelang ul on ul.language_id = lang.id and ul.unlocode_id = u.id
4932
4933 LEFT JOIN cc_airport air on air.id = t.airport_id
4934 LEFT JOIN cc_partyarea area on area.id = t.partyarea_id
4935 LEFT JOIN cc_country c on c.id = t.country_id
4936 LEFT JOIN cc_countrylang cl on cl.language_id = lang.id and cl.country_id = c.id
4937
4938
4939 LEFT JOIN cc_partyaddress cpa on cpa.id = t.customer_id
4940 LEFT JOIN cc_party cp on cp.id = cpa.party_id
4941 LEFT JOIN cc_tariffprice p on p.id = t.tariffprice_id
4942 LEFT JOIN cc_invoiceconceptlang icl on icl.parent_id = p.invoiceconcept_id and icl.language_id = lang.id
4943 LEFT JOIN cc_currency cur on cur.id = p.currency_id
4944 LEFT JOIN cc_currencylang curl on curl.language_id = lang.id and curl.parent_id = cur.id
4945 LEFT JOIN cc_tariffcontainertype pct on pct.tariffprice_id = p.id
4946 LEFT JOIN cc_containertype ct on ct.id = pct.containertype_id;
4947
4948-- TARIFF COST GENERAL HISTO;
4949-- ##############################################################################################
4950 CREATE OR REPLACE VIEW cc_tariffcostgeneralhstview AS
4951 select t.id, lang.id as language_id, t.delegation_id, t.tarifftype, t.transportmode, t.trafficflow, t
4952 .trafficchargetype, t.partyaddress_id, t.customer_id, t.fromdate, t.todate, COALESCE
4953 (ppa.name, COALESCE(pp.name_short, pp.name)) as providername
4954
4955, t.localport_id, COALESCE(lul.name, lu.name) as localportname, t.localairport_id, t.port_id, t.airport_id, lair.name as localairportname, t.partyarea_id, t.country_id
4956
4957, COALESCE(ul.name, u.name) as portname, air.name as airportname, area.name as partyareaname, COALESCE(cl.name, c.name) as countryname
4958, COALESCE(cpa.name, COALESCE(cp.name_short, cp.name)) as customername
4959, p.tariffrule, pct.containertype_id
4960, COALESCE(pct.price1, p.price1) as price1, COALESCE(pct.price2, p.price2) as price2, COALESCE(pct.pricemin, p.pricemin) as pricemin, COALESCE(pct.pricemax, p.pricemax) as pricemax, COALESCE(pct.percentage, p.percentage) as percentage
4961, p.currency_id, p
4962.invoiceconcept_id
4963, icl.name as invoiceconceptname, cur.code as currencycode, cur.symbol as currencysymbol, curl.name as currencyname
4964, ct.code as containertypecode, COALESCE(ct.name_short, ct.name) as containertypename, p.id as tariffprice_id, t.createddate, p.kgsbym3, p.kgsbylinearmeter
4965
4966 from cc_tariffcostgeneral_hst t
4967 LEFT JOIN cc_language lang on lang.isactive = 'Y'
4968 LEFT JOIN cc_partyaddress ppa on ppa.id = t.partyaddress_id
4969 LEFT JOIN cc_party pp on pp.id = ppa.party_id
4970
4971 LEFT JOIN cc_unlocode lu on lu.id = t.localport_id
4972 LEFT JOIN cc_unlocodelang lul on lul.language_id = lang.id and lul.unlocode_id = lu.id
4973
4974 LEFT JOIN cc_airport lair on lair.id = t.localairport_id
4975
4976 LEFT JOIN cc_unlocode u on u.id = t.port_id
4977 LEFT JOIN cc_unlocodelang ul on ul.language_id = lang.id and ul.unlocode_id = u.id
4978
4979 LEFT JOIN cc_airport air on air.id = t.airport_id
4980 LEFT JOIN cc_partyarea area on area.id = t.partyarea_id
4981 LEFT JOIN cc_country c on c.id = t.country_id
4982 LEFT JOIN cc_countrylang cl on cl.language_id = lang.id and cl.country_id = c.id
4983
4984
4985 LEFT JOIN cc_partyaddress cpa on cpa.id = t.customer_id
4986 LEFT JOIN cc_party cp on cp.id = cpa.party_id
4987 LEFT JOIN cc_tariffprice_hst p on p.id = t.tariffprice_id
4988 LEFT JOIN cc_invoiceconceptlang icl on icl.parent_id = p.invoiceconcept_id and icl.language_id = lang.id
4989 LEFT JOIN cc_currency cur on cur.id = p.currency_id
4990 LEFT JOIN cc_currencylang curl on curl.language_id = lang.id and curl.parent_id = cur.id
4991 LEFT JOIN cc_tariffcontainertype_hst pct on pct.tariffprice_id = p.id
4992 LEFT JOIN cc_containertype ct on ct.id = pct.containertype_id;
4993
4994-- SHIPPING LINES BY SHIPAGENT;
4995-- ##############################################################################################
4996CREATE OR REPLACE VIEW cc_shippinglinebyshipagentsview as
4997 select rel.id, rel.shippingline_id, rel.shipagent_id, COALESCE(pa.mainport_id, rel.port_id) as port_id from
4998 cc_shplinebyshpagent rel LEFT JOIN cc_partyaddress pa on pa.id = rel.shipagent_id;
4999
5000-- COMMERCIAL OFFER SERVICE;
5001-- ##############################################################################################
5002CREATE OR REPLACE VIEW cc_commercialofferserviceview AS
5003 select s.id, 'Y' as isservice, lang.id as language_id, h.delegation_id
5004 , h.id as commercialofferheader_id, h.offerdate, h.transportmode, h.trafficflow, h.trafficchargetype, h.incoterm_id, inc.code as incotermcode
5005 , h.status, h.fromdate, h.todate, h.isdangerousgoods, h.istemperaturecontrol
5006 , s.portorigin_id, COALESCE(ul1.name, u1.name) as portoriginname
5007 , s.portdestination_id, COALESCE(ul2.name, u2.name) as portdestinationname
5008 , s.portvia_id, COALESCE(ul3.name, u3.name) as portvianame
5009 , s.transittime, s.frequency_id, fl.name as frequencyname
5010 , s.seacontract_id, sc.contractnumber
5011 , s.shipagent_id, COALESCE(sapa.name, COALESCE(sap.name_short, sap.name)) as shipagentname
5012 , s.shippingline_id, COALESCE(sp.name_short, sp.name) as shippinglinename
5013 , s.consolidator_id, COALESCE(cop.name_short, cop.name) as consolidatorname
5014 , h.customer_id, COALESCE(capa.name, COALESCE(cap.name_short, cap.name)) as customername
5015 , s.airportorigin_id, s.airportdestination_id, a1.name as airportoriginname, a2.name as airportdestinationname
5016 , s.airline_id, COALESCE(pairline.name_short, pairline.name) as airlinename, s.inlandcarrier_id, COALESCE(pl.name_short, pl.name) as inlandcarriername
5017 , h.customerref
5018 , s.serviceprovided
5019 , s.placereceipt_id, COALESCE(urel.name, ure.name) as placereceiptname
5020 , s.placedelivery_id, COALESCE(udel.name, ude.name) as placedeliveryname
5021
5022 FROM cc_commercialofferservice s
5023 LEFT JOIN cc_language lang on lang.isactive = 'Y'
5024 LEFT JOIN cc_commercialofferheader h on h.id = s.commercialofferheader_id
5025 LEFT JOIN cc_unlocode u1 on u1.id = s.portorigin_id
5026 LEFT JOIN cc_unlocodelang ul1 on ul1.unlocode_id = s.portorigin_id and ul1.language_id = lang.id
5027 LEFT JOIN cc_unlocode u2 on u2.id = s.portdestination_id
5028 LEFT JOIN cc_unlocodelang ul2 on ul2.unlocode_id = s.portdestination_id and ul2.language_id = lang.id
5029 LEFT JOIN cc_unlocode u3 on u3.id = s.portvia_id
5030 LEFT JOIN cc_unlocodelang ul3 on ul3.unlocode_id = s.portvia_id and ul3.language_id = lang.id
5031 LEFT JOIN cc_frequencylang fl on fl.frequency_id = s.frequency_id and fl.language_id = lang.id
5032 LEFT JOIN cc_seacontract sc on sc.id = s.seacontract_id
5033 LEFT JOIN cc_partyaddress sapa on sapa.id = s.shipagent_id
5034 LEFT JOIN cc_party sap on sap.id = sapa.party_id
5035 LEFT JOIN cc_party sp on sp.id = s.shippingline_id
5036 LEFT JOIN cc_partyaddress copa on copa.id = s.consolidator_id
5037 LEFT JOIN cc_party cop on cop.id = copa.party_id
5038 LEFT JOIN cc_incoterm inc on inc.id = h.incoterm_id
5039 LEFT JOIN cc_partyaddress capa on capa.id = h.customer_id
5040 LEFT JOIN cc_party cap on cap.id = capa.party_id
5041 LEFT JOIN cc_airport a1 on a1.id = s.airportorigin_id
5042 LEFT JOIN cc_airport a2 on a2.id = s.airportdestination_id
5043 LEFT JOIN cc_airline al on al.id = s.airline_id
5044 LEFT JOIN cc_party pairline on pairline.id = al.party_id
5045 LEFT JOIN cc_partyaddress pla on pla.id = s.inlandcarrier_id
5046 LEFT JOIN cc_party pl on pl.id = pla.party_id
5047 LEFT JOIN cc_unlocode ure on ure.id = s.placereceipt_id
5048 LEFT JOIN cc_unlocodelang urel on urel.unlocode_id = s.placereceipt_id and urel.language_id = lang.id
5049 LEFT JOIN cc_unlocode ude on ude.id = s.placedelivery_id
5050 LEFT JOIN cc_unlocodelang udel on udel.unlocode_id = s.placedelivery_id and udel.language_id = lang.id
5051
5052 UNION
5053 select (h.id * -1) as id, 'N' as isservice, lang.id as language_id, h.delegation_id,
5054 h.id as commercialofferheader_id, h.offerdate, h.transportmode, h.trafficflow, h.trafficchargetype, h.incoterm_id, inc.code as incotermcode
5055 , h.status, h.fromdate, h.todate, h.isdangerousgoods, h.istemperaturecontrol
5056 , NULL::integer as portorigin_id, NULL::character varying as portoriginname
5057 , NULL::integer as portdestination_id, NULL::character varying as portdestinationname
5058 , NULL::integer as portvia_id, NULL::character varying as portvianame
5059 , NULL::integer as transittime, NULL::integer as frequency_id, NULL::character varying as frequencyname
5060 , NULL::integer as seacontract_id, NULL::character varying AS contractnumber
5061 , NULL::integer as shipagent_id, NULL::character varying as shipagentname
5062 , NULL::integer as shippingline_id, NULL::character varying as shippinglinename
5063 , NULL::integer as consolidator_id, NULL::character varying as consolidatorname
5064 , h.customer_id, COALESCE(capa.name, COALESCE(cap.name_short, cap.name)) as customername
5065 , NULL::integer as airportorigin_id, NULL::integer as airportdestination_id, NULL::character varying as airportoriginname, NULL::character varying as airportdestinationname
5066 , NULL::integer as airline_id, NULL::character varying as airlinename, NULL::integer as inlandcarrier_id, NULL::character varying as inlandcarriername
5067 , h.customerref
5068 , NULL::character as serviceprovided
5069 , NULL::integer as placereceipt_id, NULL::character as placereceiptname
5070 , NULL::integer as placedelivery_id, NULL::character as placedeliveryname
5071 FROM cc_commercialofferheader h
5072 LEFT JOIN cc_language lang on lang.isactive = 'Y'
5073 LEFT JOIN cc_incoterm inc on inc.id = h.incoterm_id
5074 LEFT JOIN cc_partyaddress capa on capa.id = h.customer_id
5075 LEFT JOIN cc_party cap on cap.id = capa.party_id
5076 WHERE numberofservices = 0
5077 ;
5078
5079-- LAND CARRIER DISTANCE HEADER;
5080-- ##############################################################################################
5081CREATE OR REPLACE VIEW cc_landcarrierdistanceheaderview AS
5082 select h.id, lang.id as language_id, h.inlandcarrier_id, h.locationtype, h.locationtypedetail, h.port_id, h
5083 .airport_id, h.landlocation_id, h.zipcodecountry_id, h.zipcode, h.fromzipcode, h.tozipcode
5084 , COALESCE(pa.name, COALESCE(p.name_short, p.name)) as inlandcarriername, air.name as airportname, COALESCE(portl
5085 .name, port.name) as portname, land.name as landlocationname
5086 , zip1.city as zipcodecity, zip2.city as fromzipcodecity, zip3.city as tozipcodecity, (select count(*) from
5087 cc_landcarrierdistancedetail d where d.landcarrierdistanceheader_id = h.id) as numdetails
5088 FROM cc_landcarrierdistanceheader as h
5089 LEFT JOIN cc_language lang on lang.isactive = 'Y'
5090 LEFT JOIN cc_partyaddress pa on pa.id = h.inlandcarrier_id
5091 LEFT JOIN cc_party p on p.id = pa.party_id
5092 LEFT JOIN cc_unlocodelang portl on portl.unlocode_id = h.port_id and portl.language_id = lang.id
5093 LEFT JOIN cc_unlocode port on port.id = h.port_id
5094 LEFT JOIN cc_airport air on air.id = h.airport_id
5095 LEFT JOIN cc_unlocodelang landl on landl.unlocode_id = h.landlocation_id and landl.language_id = lang.id
5096 LEFT JOIN cc_unlocode land on land.id = h.landlocation_id
5097 LEFT JOIN cc_zipcode zip1 on zip1.country_id = zipcodecountry_id and zip1.code = h.zipcode
5098 LEFT JOIN cc_zipcode zip2 on zip2.country_id = zipcodecountry_id and zip2.code = h.fromzipcode
5099 LEFT JOIN cc_zipcode zip3 on zip3.country_id = zipcodecountry_id and zip3.code = h.tozipcode
5100 ;
5101
5102-- LAND CARRIER DISTANCE DETAIL;
5103-- ##############################################################################################
5104CREATE OR REPLACE VIEW cc_landcarrierdistancedetailview AS
5105 select d.id, lang.id as language_id, d.landcarrierdistanceheader_id, d.port_id, d.airport_id, d.landlocation_id, d
5106 .zipcodecountry_id, d.zipcode, d.fromzipcode, d.tozipcode
5107 , air.name as airportname, COALESCE(portl.name, port.name) as portname, land.name as landlocationname
5108 , d.kmsdistance
5109 FROM cc_landcarrierdistancedetail as d
5110 LEFT JOIN cc_language lang on lang.isactive = 'Y'
5111 LEFT JOIN cc_unlocodelang portl on portl.unlocode_id = d.port_id and portl.language_id = lang.id
5112 LEFT JOIN cc_unlocode port on port.id = d.port_id
5113 LEFT JOIN cc_airport air on air.id = d.airport_id
5114 LEFT JOIN cc_unlocodelang landl on landl.unlocode_id = d.landlocation_id and landl.language_id = lang.id
5115 LEFT JOIN cc_unlocode land on land.id = d.landlocation_id
5116 ;
5117
5118-- COMMERCIAL POLICY HEADER VIEW;
5119-- ##############################################################################################
5120CREATE OR REPLACE VIEW cc_commercialpolicyheaderview AS
5121 select h.id, h.company_id, lang.id as language_id, l.name as name
5122 FROM cc_commercialpolicyheader as h
5123 LEFT JOIN cc_language lang on lang.isactive = 'Y'
5124 LEFT JOIN cc_commercialpolicylang as l on l.commercialpolicyheader_id = h.id and l.language_id = lang.id;
5125
5126-- WAREHOUSE MOVEMENTS VIEW;
5127-- ##############################################################################################
5128CREATE OR REPLACE VIEW cc_warehousemovementview AS
5129 select m.id, m.delegation_id, lang.id as language_id, m.warehousemovementtype_id, wtl.name as warehousemovementtypename, m.party_id, COALESCE(p.name_short, p.name) as partyname, m.status
5130 , m.createdby_id, uc.name as createdname, m.assigneduser_id, ua.name as assignedusername, m.finisheduser_id, uf.name as finishedusername
5131 , m.createddate, m.assignedTime, m.finishedtime, m.failedreason_id, wrl.name as warehousemovementfailedreasonname, m.failedreason
5132 , m.originlocationtype, m.originparkingarea_id, po.name as originparkingareaname, m.origindock_id, doc.name as origindockname
5133 , m.destinationlocationtype, m.destinationparkingarea_id, pd.name as destinationparkingareaname, m.destinationdock_id, dd.name as destinationdockname
5134 , m.vehicle_id, v.vehicletype, v.licenseplate, v.description as vehicledescription, m.platformregistrationnumber
5135 , po.warehouseparking_id as originparking_id, pd.warehouseparking_id as destinationparking_id, pao.id as originwarehouse_id, pad.id as destinationwarehouse_id
5136 , pko.name as originparking, pkd.name as destinationparking
5137 , COALESCE(pao.name, COALESCE(pta.name_short, pta.name)) as originwarehouse, COALESCE(pad.name, COALESCE(ptd.name_short, ptd.name)) as destinationwarehouse
5138 , m.photography1_id, m.photography2_id, m.movementdate, m.sequence
5139
5140 FROM cc_warehousemovement m
5141 LEFT JOIN cc_party p on p.id = m.party_id
5142 LEFT JOIN cc_useraccess ua on ua.id = m.assigneduser_id
5143 LEFT JOIN cc_useraccess uc on uc.id = m.createdby_id
5144 LEFT JOIN cc_useraccess uf on uf.id = m.finisheduser_id
5145 LEFT JOIN cc_language lang on lang.isactive = 'Y'
5146 LEFT JOIN cc_warehousemovementtypelang wtl on wtl.warehousemovementtype_id = m.warehousemovementtype_id and wtl.language_id = lang.id
5147 LEFT JOIN cc_warehousemovementfailedreasonlang wrl on wrl.warehousemovementfailedreason_id = m.failedreason_id and wrl.language_id = lang.id
5148 LEFT JOIN cc_warehouseparkingarea po on po.id = m.originparkingarea_id
5149 LEFT JOIN cc_warehouseparking pko on pko.id = po.warehouseparking_id
5150 LEFT JOIN cc_warehousedock doc on doc.id = m.origindock_id
5151 LEFT JOIN cc_warehouseparkingarea pd on pd.id = m.destinationparkingarea_id
5152 LEFT JOIN cc_warehouseparking pkd on pkd.id = pd.warehouseparking_id
5153 LEFT JOIN cc_warehousedock dd on dd.id = m.destinationdock_id
5154 LEFT JOIN cc_vehicle v on v.id = m.vehicle_id
5155 LEFT JOIN cc_partyaddress pao on pao.id = COALESCE(pko.partyaddress_id, doc.partyaddress_id)
5156 LEFT JOIN cc_party pta on pta.id = pao.party_id
5157 LEFT JOIN cc_partyaddress pad on pad.id = COALESCE(pkd.partyaddress_id, dd.partyaddress_id)
5158 LEFT JOIN cc_party ptd on ptd.id = pad.party_id;
5159
5160-- WAREHOUSE MOVEMENTS TYPE VIEW;
5161-- ##############################################################################################
5162 CREATE OR REPLACE VIEW cc_warehousemovementtypeview AS
5163 Select m.company_id, m.id, l.language_id, l.name as name
5164 FROM cc_warehousemovementtype m
5165 LEFT JOIN cc_warehousemovementtypelang l on l.warehousemovementtype_id = m.id;
5166
5167-- WAREHOUSE MOVEMENTS TYPE VIEW;
5168-- ##############################################################################################
5169 CREATE OR REPLACE VIEW cc_warehousemovementfailedreasonview AS
5170 SELECT r.id, l.name, r.company_id, l.language_id
5171 FROM cc_warehousemovementfailedreason r
5172 LEFT JOIN cc_warehousemovementfailedreasonlang l on l.warehousemovementfailedreason_id = r.id;
5173
5174-- WAREHOUSE PARKING AREA VIEW;
5175-- ##############################################################################################
5176 CREATE OR REPLACE VIEW cc_warehouseparkingview AS
5177 select a.id, a.name as parkingareaname, pk.name as parkingname, pk.partyaddress_id, p.id as party_id, p.company_id
5178 from cc_warehouseparkingarea a
5179 LEFT JOIN cc_warehouseparking pk on pk.id = a.warehouseparking_id
5180 LEFT JOIN cc_partyaddress pa on pa.id = pk.partyaddress_id
5181 LEFT JOIN cc_party p on p.id = pa.party_id;
5182
5183
5184-- WAREHOUSE DOCK VIEW;
5185-- ##############################################################################################
5186 CREATE OR REPLACE VIEW cc_warehousedockview AS
5187 select d.id, d.name, d.partyaddress_id, p.id as party_id, p.company_id, pa.name as partyaddressname
5188 from cc_warehousedock d
5189 LEFT JOIN cc_partyaddress pa on pa.id = d.partyaddress_id
5190 LEFT JOIN cc_party p on p.id = pa.party_id;
5191
5192-- WAREHOUSE PARKING AREA VIEW;
5193-- ##############################################################################################
5194 CREATE OR REPLACE VIEW cc_warehouseparkingareaview AS
5195 select pa.id, p.partyaddress_id, pa.warehouseparking_id, p.name as parkingname, pa.name as areaname
5196 FROM cc_warehouseparkingarea pa
5197 LEFT JOIN cc_warehouseparking p on p.id = pa.warehouseparking_id;
5198
5199-- WORK SHIFT VIEW;
5200-- ##############################################################################################
5201 CREATE OR REPLACE VIEW cc_workshiftview AS
5202 select w.id, l.id as language_id, wl.name, w.partyaddress_id, w.sundayfromtime, w.sundaytotime, w.mondayfromtime, w.mondaytotime, w.tuesdayfromtime, w.tuesdaytotime, w.wednesdayfromtime, w.wednesdaytotime, w.thursdayfromtime, w.thursdaytotime, w.fridayfromtime, w.fridaytotime, w.saturdayfromtime, w.saturdaytotime
5203 ,w.isextratime
5204 FROM cc_workshift w
5205 LEFT JOIN cc_language l on l.isactive = 'Y'
5206 LEFT JOIN cc_workshiftlang wl on wl.language_id = l.id and wl.workshift_id = w.id;
5207
5208-- BANK VIEW;
5209-- ##############################################################################################
5210 create view cc_bankview as
5211 select b.id, b.banktype, b.code, b.name, b.country_id, b.bic, c.name as countryname,lang.id as language_id
5212 FROM cc_bank b
5213 LEFT JOIN cc_language lang on lang.isactive = 'Y'
5214 LEFT JOIN cc_countrylang cl on cl.language_id = lang.id and cl.country_id = b.country_id
5215 LEFT JOIN cc_country c on c.id = b.country_id;
5216
5217-- CAPTUREBYCONTAINER VIEW;
5218-- ##############################################################################################
5219create view cc_capturebycontainerview as
5220 select ft.file_id, p.taxid as shipagenttaxid, ftc.containerplate, ft.summarydeclaration, ft.etd - '90 day'::interval as etd
5221 from cc_filetraffic ft
5222 left join cc_partyaddress pa on ft.shipagent_id = pa.id
5223 left join cc_party p on pa.party_id = p.id
5224 left join cc_filetrafficcontainer ftc on ft.id = ftc.filetraffic_id
5225 where ft.shipagent_id is not null
5226 and ftc.containerplate is not null;
5227
5228-- ENTREGUESE VIEW;
5229-- ##############################################################################################
5230create view cc_entregueseview as
5231 select
5232 ent.isactive, fd.file_id, fd.id as filedocument_id, ent.id as entreguese_id, edi.id as messageedi_id, cnt.filetrafficcontainer_id, ent.entreguesenumber, ent.bookingnumber, ent.goodsdeclarationnumber as summarydeclaration, ent.shipagenttaxid, edi.messageplatform, edi.messagereference, edi.referencedmessage, edi.function, edi.dategenerated
5233 from cc_filedocument fd
5234 left join cc_entreguese ent on fd.id = ent.filedocument_id
5235 left join cc_messageedi edi on fd.messageedi_id = edi.id
5236 left join cc_entreguesecontainer cnt on ent.id = cnt.entreguese_id
5237 where ent.id is not null and edi.id is not null;
5238
5239-- ADMITASE VIEW;
5240-- ##############################################################################################
5241create view cc_admitaseview as
5242 select
5243 adm.isactive, fd.file_id, fd.id as filedocument_id, adm.id as admitase_id, edi.id as messageedi_id, cnt.filetrafficcontainer_id, adm.admitasenumber, adm.bookingnumber, adm.summarydeclaration, adm.shipagenttaxid, edi.messageplatform, edi.messagereference, edi.referencedmessage, edi.function, edi.dategenerated
5244 from cc_filedocument fd
5245 left join cc_admitase adm on fd.id = adm.filedocument_id
5246 left join cc_messageedi edi on fd.messageedi_id = edi.id
5247 left join cc_admitasecontainer cnt on adm.id = cnt.admitase_id
5248 where adm.id is not null and edi.id is not null;
5249
5250
5251-- INVOICES PENDING ACCOUNTING;
5252-- ##############################################################################################
5253CREATE OR REPLACE VIEW cc_invoicespendingaccountingview AS
5254 select i.delegation_id, 'SALE' as invoicescope, i.id, i.name AS invoicename, p.name as partyname, i.accountingstatus
5255 FROM cc_saleinvoiceheader i
5256 LEFT JOIN cc_partyaddress pa on pa.id = i.customer_id
5257 LEFT JOIN cc_party p on p.id = pa.party_id
5258 where i.accountingstatus <> 'SUCCESS' and i.iscompleted = 'Y'
5259 UNION
5260 select i.delegation_id, 'PURCHASE' as invoicescope, i.id, i.name AS invoicename, p.name as partyname, i
5261 .accountingstatus
5262 FROM cc_purchaseinvoiceheader i
5263 LEFT JOIN cc_partyaddress pa on pa.id = i.vendor_id
5264 LEFT JOIN cc_party p on p.id = pa.party_id
5265 where i.accountingstatus <> 'SUCCESS' and i.iscompleted = 'Y';
5266
5267-- COMMERCIAL OFFER FOOTERS;
5268-- ##############################################################################################
5269CREATE OR REPLACE VIEW cc_commercialofferfooterview AS
5270 select t.id, t.delegation_id, tl.language_id, tl.name, tl.footer
5271 FROM cc_commercialofferfooter t
5272 LEFT JOIN cc_commercialofferfooterlang tl on tl.commercialofferfooter_id = t.id;
5273
5274
5275-- COMMERCIAL OFFER FOOTER DETAIL;
5276-- ##############################################################################################
5277 CREATE OR REPLACE VIEW cc_tarifftemplatedetailview AS
5278 select td.id, td.tarifftemplateheader_id, td.description, td.isapplywithoutdocument, td.tariffprice_id, lang.id as language_id, icl.name as invoiceconceptname, ictl.name as invoiceconcepttypename, ic.printorder AS invoiceconceptprintorder, ict.printorder AS invoiceconcepttypeprintorder
5279 FROM cc_tarifftemplatedetail td
5280 LEFT JOIN cc_language lang on lang.isactive = 'Y'
5281 LEFT JOIN cc_tariffprice pr on pr.id = td.tariffprice_id
5282 LEFT JOIN cc_invoiceconceptlang icl on icl.parent_id = pr.invoiceconcept_id and icl.language_id = lang.id
5283 LEFT JOIN cc_invoiceconcept ic on ic.id = pr.invoiceconcept_id
5284 LEFT JOIN cc_invoiceconcepttype ict on ict.id = ic.invoiceconcepttype_id
5285 LEFT JOIN cc_invoiceconcepttypelang ictl on ictl.language_id = lang.id and ictl.parent_id = ict.id;
5286
5287-- COMMERCIAL OFFER EXPENSE PRICE;
5288-- ##############################################################################################
5289CREATE OR REPLACE VIEW cc_commercialoffergeneralexpensepriceview AS
5290 select ep.id
5291 , ep.commercialoffergeneralexpense_id
5292 , ep.sequence
5293 , ep.tarifftype
5294 , ep.invoiceconcept_id
5295 , ep.pricemode
5296 , ep.pricebycontainertype
5297 , ep.saletariffprice_id
5298 , ep.costtariffprice_id
5299 , ep.overridecosttariffpricegeneral_id
5300 , ep.amountgeneral
5301 , ep.amountcontainer1
5302 , ep.amountcontainer2
5303 , ep.amountcontainer3
5304 , ep.amountcontainer4
5305 , ep.costamountgeneral
5306 , ep.costamountcontainer1
5307 , ep.costamountcontainer2
5308 , ep.costamountcontainer3
5309 , ep.costamountcontainer4
5310 , ep.origin_id
5311 , ep.destination_id
5312 , ep.kmsdistance
5313 , ep.description
5314 , ep.isapplywithoutdocument
5315 , ic.printorder as invoiceconceptprintorder
5316 , ict.printorder as invoiceconcepttypeprintorder
5317
5318 FROM cc_commercialoffergeneralexpenseprice ep
5319 LEFT JOIN cc_invoiceconcept ic on ic.id = ep.invoiceconcept_id
5320 LEFT JOIN cc_invoiceconcepttype ict on ict.id = ic.invoiceconcepttype_id;
5321
5322-- TARIFF TEMPLATE HEADER LANG;
5323-- ##############################################################################################
5324CREATE OR REPLACE VIEW cc_tarifftemplateview AS
5325 select t.id, t.delegation_id, tl.language_id, tl.name, t.tarifftype
5326 FROM cc_tarifftemplateheader t
5327 LEFT JOIN cc_tarifftemplateheaderlang tl on tl.tarifftemplateheader_id = t.id;
5328
5329-- PARTY GROUP;
5330-- ##############################################################################################
5331CREATE OR REPLACE VIEW cc_partygroupview AS
5332 select t.id, t.delegation_id, tl.language_id, tl.name, t.printlist_id, pll.name as printlistname, t.language_id as partygrouplanguage_id
5333 , lan2.name as partygrouplanguagename, t.partygrouptype
5334 FROM cc_partygroup t
5335 LEFT JOIN cc_language lang on lang.isactive = 'Y'
5336 LEFT JOIN cc_partygrouplang tl on tl.partygroup_id = t.id and tl.language_id = lang.id
5337 LEFT JOIN cc_printlist pl on pl.id = t.printlist_id
5338 LEFT JOIN cc_printlistlang pll on pll.printlist_id = t.printlist_id and pll.language_id = lang.id
5339 LEFT JOIN cc_language lan2 on lan2.id = t.language_id;
5340
5341-- PARTY GROUP DETAIL;
5342-- ##############################################################################################
5343CREATE OR REPLACE VIEW cc_partygroupdetailview AS
5344 SELECT d.id, h.id as partygroup_id, d.partyaddress_id, lang.id as language_id, COALESCE(p.name_short, p.name) as partyname, p.taxid, COALESCE(coul.name, cou.name) as countryname
5345 , h.partygrouptype
5346 FROM cc_partygroupdetail d
5347 LEFT JOIN cc_partygroup h on h.id = d.partygroup_id
5348 LEFT JOIN cc_language lang on lang.isactive = 'Y'
5349 LEFT JOIN cc_partyaddress pa on pa.id = d.partyaddress_id
5350 LEFT JOIN cc_party p on p.id = pa.party_id
5351 LEFT JOIN cc_country cou on cou.id = p.country_id
5352 LEFT JOIN cc_countrylang coul on coul.country_id = p.country_id and coul.language_id = lang.id;
5353
5354-- PRINT LIST;
5355-- ##############################################################################################
5356CREATE OR REPLACE VIEW cc_printlistview AS
5357 select t.id, tl.language_id, tl.name, tl.description, t.code
5358 FROM cc_printlist t
5359 LEFT JOIN cc_printlistlang tl on tl.printlist_id = t.id;
5360
5361-- PRINT LIST HISTO;
5362-- ##############################################################################################
5363 CREATE OR REPLACE VIEW cc_printlisthistoview AS
5364 select h.id, h.printlist_id, lang.id as language_id, ptl.name as printlistname, COALESCE(pgl.name, COALESCE(p.name_short, p.name)) as customername, h.transportmode, h.trafficflow,
5365 COALESCE(spa.name, COALESCE(sp.name_short, sp.name)) as shippername, COALESCE(cpa.name, COALESCE(cp.name_short, cp.name)) as consigneename
5366 , COALESCE(cor.name_short, cor.name) as correspondentname, COALESCE(nw.name_short, nw.name) as networkname
5367 , COALESCE(col.name, co.name) as countryoriginname, COALESCE(cdl.name, cd.name) as countrydestinationname
5368 , inc.code as incotermcode, h.servicedatefrom, h.servicedateto, h.createddate, us.name as username
5369
5370 FROM cc_printlisthisto h
5371 LEFT JOIN cc_language lang on lang.isactive = 'Y'
5372 LEFT JOIN cc_printlistlang ptl on ptl.id = h.printlist_id and ptl.language_id = lang.id
5373 LEFT JOIN cc_partyaddress pa on pa.id = h.customer_id
5374 LEFT JOIN cc_party p on p.id = pa.party_id
5375 LEFT JOIN cc_partygrouplang pgl on pgl.partygroup_id = h.partygroup_id and pgl.language_id = lang.id
5376 LEFT JOIN cc_partyaddress spa on spa.id = h.shipper_id
5377 LEFT JOIN cc_party sp on sp.id = spa.party_id
5378 LEFT JOIN cc_partyaddress cpa on cpa.id = h.consignee_id
5379 LEFT JOIN cc_party cp on cp.id = cpa.party_id
5380 LEFT JOIN cc_party cor on cor.id = h.correspondent_id
5381 LEFT JOIN cc_party nw on nw.id = h.agentnetwork_id
5382 LEFT JOIN cc_country co on co.id = h.countryorigin_id
5383 LEFT JOIN cc_countrylang col on col.country_id = h.countryorigin_id and col.language_id = lang.id
5384 LEFT JOIN cc_country cd on cd.id = h.countrydestination_id
5385 LEFT JOIN cc_countrylang cdl on cdl.country_id = h.countrydestination_id and cdl.language_id = lang.id
5386 LEFT JOIN cc_incoterm inc on inc.id = h.incoterm_id
5387 LEFT JOIN cc_useraccess us on us.id = h.createdby_id;
5388
5389-- BASF FILE;
5390-- ##############################################################################################
5391 CREATE OR REPLACE VIEW cc_basffileview AS
5392 select p.delegation_id, p.id as process_id, f.id, f.filename, f.originalfilename, f.status, f.dataflow, p.emailfrom, p.receiveddate from cc_basffile f LEFT JOIN cc_basfprocess p on f.basfprocess_id = p.id;
5393
5394-- BASF SHIPMENT;
5395-- ##############################################################################################
5396CREATE OR REPLACE VIEW cc_basfshipmentview AS
5397
5398 select s.id, s.basffile_id, s.remitente, s.recogidaentregavacio, s.poblacionremitente, s.postalremitente, s.paisremitente, s.destinatario, s.poblaciondestinatario, s.postaldestinatario, s.paisdestinatario, s.admitase, s.expedicion, s.referencia, s.contenedor, s.refequipamiento, s.booking
5399 , s.status, s.statusdate, s.statusplace
5400 , s.placereceipt_id, s.countryreceipt_id, s.provincereceipt_id, s.placedelivery_id, s.countrydelivery_id, s.provincedelivery_id, s.portload_id, s.portunload_id, s.closed, s.sendpending, s.errortext
5401 , u1.code as placereiptcode, u2.code as placedeliverycode, u3.code as portloadcode, u4.code as portunloadcode
5402 , cou1.code as countryreceiptcode, cou2.code as countrydeliverycode, s.createddate, p.delegation_id, s.direccionremitente
5403 , COALESCE(pro1.name, 'BARCELONA') as provincereceiptname, COALESCE(pro2.name, 'BARCELONA') as provincedeliveryname
5404 , s.updatedstatusdate, f1.originalfilename as inputfilename, f2.originalfilename as outputfilename, f1.status as inputfilestatus, f2.status as outputfilestatus
5405 , f1.filename as completeinputfile, f2.filename as completeoutputfile
5406
5407 from cc_basfshipment s
5408 LEFT JOIN cc_basffile f1 on f1.id = s.basffile_id
5409 LEFT JOIN cc_basffile f2 on f2.id = s.outputbasffile_id
5410 LEFT JOIN cc_basfprocess p on p.id = f1.basfprocess_id
5411 LEFT JOIN cc_unlocode u1 on u1.id = s.placereceipt_id
5412 LEFT JOIN cc_unlocode u2 on u2.id = s.placedelivery_id
5413 LEFT JOIN cc_unlocode u3 on u3.id = s.portload_id
5414 LEFT JOIN cc_unlocode u4 on u4.id = s.portunload_id
5415 LEFT JOIN cc_country cou1 on cou1.id = s.countryreceipt_id
5416 LEFT JOIN cc_country cou2 on cou2.id = s.countrydelivery_id
5417 LEFT JOIN cc_province pro1 on pro1.id = s.provincereceipt_id
5418 LEFT JOIN cc_province pro2 on pro2.id = s.provincedelivery_id;
5419
5420-- SPECIAL HANDLING CODES;
5421-- ##############################################################################################
5422 CREATE OR REPLACE VIEW cc_specialhandlingcodeview AS
5423 select m.id, m.code, l.id as language_id, lm.name
5424 FROM cc_specialhandlingcode m
5425 LEFT JOIN cc_language l on l.isactive = 'Y'
5426 LEFT JOIN cc_specialhandlingcodelang lm on lm.specialhandlingcode_id = m.id and lm.language_id = l.id;
5427
5428-- AWB SPECIAL HANDLING CODES;
5429-- ##############################################################################################
5430CREATE OR REPLACE VIEW cc_awbspecialhandlingview AS
5431 select aws.id, s.id as specialhandlingcode_id, s.code as code, aws.awbheader_id
5432 FROM cc_awbspecialhandlingcode aws
5433 LEFT JOIN cc_specialhandlingcode s on s.id = aws.specialhandlingcode_id;
5434
5435-- SALE INVOICE DUE DATES AE VIEW;
5436-- ##############################################################################################
5437CREATE OR REPLACE VIEW cc_saleinvoiceduedatea3view AS
5438 SELECT i.delegation_id, d.id, i.name, d.parent_id as saleinvoiceheader_id, d.duedate, d.amount, i.invoiceida3, i.walletida3, d.ida3, p.name as partyname, i.invoicedate
5439 , (COALESCE(i.exchange, 1) * d.amount) as companyamount, cur.code as currencycode, curdel.code as delcurrencycode
5440 from cc_saleinvoiceduedate d
5441 LEFT JOIN cc_saleinvoiceheader i on i.id = d.parent_id
5442 LEFT JOIN cc_partyaddress pa on pa.id = i.customer_id
5443 LEFT JOIN cc_party p on p.id = pa.party_id
5444 LEFT JOIN cc_currency cur ON cur.id = i.currency_id
5445 LEFT JOIN cc_delegation del on del.id = i.delegation_id
5446 LEFT JOIN cc_currency curdel ON curdel.id = del.currency_id
5447 WHERE d.ida3 IS NOT NULL;
5448
5449
5450
5451-- PURCHASE INVOICE DUE DATES AE VIEW;
5452-- ##############################################################################################
5453CREATE OR REPLACE VIEW cc_purchaseinvoiceduedatea3view AS
5454 SELECT i.delegation_id, d.id, i.name, d.parent_id as purchaseinvoiceheader_id, d.duedate, d.amount, i.invoiceida3, i.walletida3, d.ida3, p.name as partyname, i.invoicedate
5455 , (COALESCE(i.exchange, 1) * d.amount) as companyamount, cur.code as currencycode, curdel.code as delcurrencycode
5456 from cc_purchaseinvoiceduedate d
5457 LEFT JOIN cc_purchaseinvoiceheader i on i.id = d.parent_id
5458 LEFT JOIN cc_partyaddress pa on pa.id = i.vendor_id
5459 LEFT JOIN cc_party p on p.id = pa.party_id
5460 LEFT JOIN cc_delegation del on del.id = i.delegation_id
5461 LEFT JOIN cc_currency cur ON cur.id = i.currency_id
5462 LEFT JOIN cc_currency curdel ON curdel.id = del.currency_id
5463 WHERE d.ida3 IS NOT NULL;
5464
5465-- GROUP SHIPMENT TRAFFIC;
5466-- ##############################################################################################
5467CREATE OR REPLACE VIEW cc_shipmenttrafficairgroupedview
5468 AS select delegation_id, airportorigin_id, airportdestination_id, customer_id, correspondent_id, incoterm_id, max(id) AS shipment_id from cc_shipmenttrafficair
5469 group by delegation_id, airportorigin_id, airportdestination_id, customer_id, correspondent_id, incoterm_id
5470 order by delegation_id, airportorigin_id, airportdestination_id, customer_id, correspondent_id, incoterm_id;
5471
5472-- FILE WITH GRM SYNCHRONIZE STATUS IS ERROR;
5473-- ##############################################################################################
5474 CREATE OR REPLACE VIEW cc_filegrmerror
5475 AS SELECT f.delegation_id, f.id, COALESCE(shp.name, f.name) as filename, f.isfile, f.createddate, f.updateddate, us1.code as createdbyusercode, us2.code as updatedbyusercode, f.grmlastactionstatus
5476 FROM cc_file f
5477 LEFT JOIN cc_shipment shp on shp.file_id = f.id
5478 LEFT JOIN cc_useraccess us1 on us1.id = f.createdby_id
5479 LEFT JOIN cc_useraccess us2 on us2.id = f.updated_id
5480 WHERE f.grmsyncstatus = 'ERROR';
5481
5482-- SHIPMENT WITH GRM SYNCHRONIZE STATUS IS ERROR;
5483-- ##############################################################################################
5484CREATE OR REPLACE VIEW cc_shipmentgrmerror
5485 AS SELECT f.delegation_id, shp.id, shp.name, shp.createddate, shp.updateddate, us1.code as createdbyusercode, us2.code as updatedbyusercode, shp.grmlastactionstatus
5486 FROM cc_shipment shp
5487 LEFT JOIN cc_file f on f.id = shp.file_id
5488 LEFT JOIN cc_useraccess us1 on us1.id = shp.createdby_id
5489 LEFT JOIN cc_useraccess us2 on us2.id = shp.updated_id
5490 WHERE shp.grmsyncstatus = 'ERROR';
5491
5492-- FILE TRAFFIC CONTAINER WITH GRM SYNCHRONIZE STATUS IS ERROR;
5493-- ##############################################################################################
5494CREATE OR REPLACE VIEW cc_filetrafficcontainergrmerror
5495 AS SELECT f.delegation_id, cnt.id, COALESCE(cnt.carrierreference, cnt.containerplate) as name, cnt.createddate, cnt.updateddate, us1.code as createdbyusercode, us2.code as updatedbyusercode, cnt.grmlastactionstatus
5496 FROM cc_filetrafficcontainer cnt
5497 LEFT JOIN cc_filetraffic ftr on ftr.id = cnt.filetraffic_id
5498 LEFT JOIN cc_file f on f.id = ftr.file_id
5499 LEFT JOIN cc_useraccess us1 on us1.id = cnt.createdby_id
5500 LEFT JOIN cc_useraccess us2 on us2.id = cnt.updated_id
5501 WHERE cnt.grmsyncstatus = 'ERROR';
5502
5503-- SALE INVOICES WITH GRM SYNCHRONIZE STATUS IS ERROR;
5504-- ##############################################################################################
5505CREATE OR REPLACE VIEW cc_saleinvoicegrmerror
5506 AS SELECT inv.delegation_id, inv.id, inv.name, inv.createddate, inv.updateddate, us1.code as createdbyusercode, us2.code as updatedbyusercode, inv.grmlastactionstatus
5507 FROM cc_saleinvoiceheader inv
5508 LEFT JOIN cc_useraccess us1 on us1.id = inv.createdby_id
5509 LEFT JOIN cc_useraccess us2 on us2.id = inv.updated_id
5510 WHERE inv.grmsyncstatus = 'ERROR';
5511
5512
5513-- PARTY EVALUATION GDP VIEW ;
5514-- ##############################################################################################
5515CREATE OR REPLACE VIEW cc_partyevaluationgdpview
5516 AS SELECT
5517 cp.id,
5518 cp.name,
5519 cp.taxid,
5520 cp.evaluation,
5521 CASE WHEN cp.evaluation IS NULL THEN '' ELSE (select range.icon from cc_form_evaluation_gdp_evaluation_range range where range.percentage >= cp.evaluation ORDER BY range.percentage ASC LIMIT 1) END as icon,
5522 CASE WHEN cp.evaluation IS NULL THEN '' ELSE (select range.styleclass from cc_form_evaluation_gdp_evaluation_range range where range.percentage >= cp.evaluation ORDER BY range.percentage ASC LIMIT 1) END as styleclass,
5523 COUNT(evaluation.userid) as numberEvaluations,
5524 company.id as companyId,
5525 cp.iscustomer,
5526 cp.isvendor,
5527 cp.isagent,
5528 cp.isfreightforwarder,
5529 cp.isshippingline,
5530 cp.isshippingagent,
5531 cp.isairline,
5532 cp.isgsa,
5533 cp.istruck,
5534 cp.ishandlingagent,
5535 cp.isnvocc,
5536 cp.iswarehouse,
5537 cp.ispcs,
5538 cp.isportterminal,
5539 cp.isinsurancecompany,
5540 cp.iscustomsagent,
5541 cp.issalesrepresentative,
5542 cp.ispotential,
5543 cp.isweighercenter
5544 FROM cc_form_evaluation_gdp evaluation
5545 RIGHT OUTER JOIN cc_party cp on evaluation.party = cp.id
5546 INNER JOIN cc_company company ON company.id = cp.company_id
5547 WHERE cp.isgdp = 'Y'
5548 GROUP BY cp.id, companyId;
5549
5550-- COMMERCIAL OFFER PROFIT ;
5551-- ##############################################################################################
5552CREATE OR REPLACE VIEW cc_commercialofferprofitview AS
5553 SELECT p.id, p.commercialofferservice_id, p.commercialofferheader_id, p.invoiceconcept_id, lang.id as language_id, CASE WHEN p.description IS NOT NULL and p.description <> '' THEN p.description ELSE il.name END as invoiceconceptname
5554 , i.printorder as invoiceconceptprintorder, ict.printorder as invoiceconcepttypeprintorder
5555 , p.salecurrency_id, p.saleunits, p.saleprice, cursale.decimals as salecurrencydecimals, cursale.symbol as salecurrencysymbol, cursale.code as salecurrencycode, cursale.currencysymbolpos as salecurrencysymbolpos
5556 , p.costcurrency_id, p.costunits, p.costprice, curcost.decimals as costcurrencydecimals, curcost.symbol as costcurrencysymbol, curcost.code as costcurrencycode, curcost.currencysymbolpos as costcurrencysymbolpos
5557 , COALESCE(cnt.name_short, cnt.name) as containertypename
5558 , ser.transittime, fl.name as frequencyname
5559 , COALESCE(unol.name, uno.name) as unlocodeoriginname, COALESCE(undl.name, und.name) as unlocodedestinationname, COALESCE(unvl.name, unv.name) as unlocodevianame
5560 , COALESCE(sl.name_short, sl.name) as shippinglinename
5561 , airo.name as airportoriginname, aird.name as airportdestinationname
5562 , COALESCE(pa.name_short, pa.name) as airlinename
5563 , COALESCE(inp.name_short, inp.name) as inlandcarriername
5564 , COALESCE(cop.name_short, cop.name) as consolidatorname
5565 , cnt.printorder as containertypeprintorder, p.description
5566
5567 FROM cc_commercialofferprofit p
5568 LEFT JOIN cc_commercialofferservice ser on ser.id = p.commercialofferservice_id
5569 LEFT JOIN cc_language lang on lang.isactive = 'Y'
5570 LEFT JOIN cc_currency cursale on cursale.id = p.salecurrency_id
5571 LEFT JOIN cc_currency curcost on curcost.id = p.costcurrency_id
5572 LEFT JOIN cc_containertype cnt on cnt.id = p.containertype_id
5573 LEFT JOIN cc_invoiceconceptlang il on il.parent_id = p.invoiceconcept_id and il.language_id = lang.id
5574 LEFT JOIN cc_invoiceconcept i on i.id = p.invoiceconcept_id
5575 LEFT JOIN cc_invoiceconcepttype ict on ict.id = i.invoiceconcepttype_id
5576 LEFT JOIN cc_unlocodelang unol on unol.unlocode_id = ser.portorigin_id and unol.language_id = lang.id
5577 LEFT JOIN cc_unlocode uno on uno.id = ser.portorigin_id
5578 LEFT JOIN cc_unlocodelang undl on undl.unlocode_id = ser.portdestination_id and undl.language_id = lang.id
5579 LEFT JOIN cc_unlocode und on und.id = ser.portdestination_id
5580 LEFT JOIN cc_unlocodelang unvl on unvl.unlocode_id = ser.portvia_id and unvl.language_id = lang.id
5581 LEFT JOIN cc_unlocode unv on unv.id = ser.portvia_id
5582 LEFT JOIN cc_party sl on sl.id = ser.shippingline_id
5583 LEFT JOIN cc_airport airo on airo.id = ser.airportorigin_id
5584 LEFT JOIN cc_airport aird on aird.id = ser.airportdestination_id
5585 LEFT JOIN cc_airline airl on airl.id = ser.airline_id
5586 LEFT JOIN cc_party pa on pa.id = airl.party_id
5587 LEFT JOIN cc_frequencylang fl on fl.frequency_id = ser.frequency_id and fl.language_id = lang.id
5588 LEFT JOIN cc_partyaddress inpa on inpa.id = ser.inlandcarrier_id
5589 LEFT JOIN cc_party inp on inp.id = inpa.party_id
5590 LEFT JOIN cc_partyaddress copa on copa.id = ser.consolidator_id
5591 LEFT JOIN cc_party cop on cop.id = copa.party_id;
5592
5593
5594-- ACTIVITY ;
5595-- ##############################################################################################
5596 CREATE OR REPLACE VIEW cc_activityview AS
5597 select a.id, a.code, lang.id as language_id, al.name as name
5598 FROM cc_activity a
5599 LEFT JOIN cc_language lang on lang.isactive = 'Y'
5600 LEFT JOIN cc_activitylang al on al.language_id = lang.id and al.activity_id = a.id;
5601
5602
5603-- ORIGINAL DOCUMENT LETTER CONFIGURATION ;
5604-- ##############################################################################################
5605 CREATE OR REPLACE VIEW cc_originaldocumentletterconfheaderview AS
5606 SELECT h.id, h.transportmode, h.trafficflow, h.trafficchargetype, lang.id as language_id, hl.name as name, hl.text as description
5607 FROM cc_originaldocumentletterconfheader AS h
5608 LEFT JOIN cc_language lang on lang.isactive = 'Y'
5609 LEFT JOIN cc_originaldocumentletterconfheaderlang hl ON hl.language_id = lang.id AND hl.originaldocumentletterconfheader_id = h.id;
5610
5611-- BUSQUEDA DE CONTENEDOR CON ENTREGUSE;
5612-- ##############################################################################################
5613CREATE OR REPLACE VIEW cc_oldestcontainerforentregueseview AS
5614 select ftc.filetraffic_id, ftc.id as filetrafficcontainer_id, ec.sequence, ec.createddate as createddateentreguese
5615 from cc_filetrafficcontainer ftc
5616 left join cc_entreguesecontainer ec on ec.filetrafficcontainer_id = ftc.id
5617 order by ec.createddate, sequence asc
5618 limit 1;
5619
5620-- BUSQUEDA DE CONTENEDOR CON ADMITASE;
5621-- ##############################################################################################
5622CREATE OR REPLACE VIEW cc_oldestcontainerforadmitaseview AS
5623 select ftc.filetraffic_id, ftc.id as filetrafficcontainer_id, ac.sequence, ac.createddate as createddateadmitase
5624 from cc_filetrafficcontainer ftc
5625 left join cc_admitasecontainer ac on ac.filetrafficcontainer_id = ftc.id
5626 order by ac.createddate, sequence asc
5627 limit 1;
5628
5629-- CONTACT TYPE ;
5630-- ##############################################################################################
5631CREATE OR REPLACE VIEW cc_contacttypeview AS
5632 select a.id, a.code, lang.id as language_id, al.name as name
5633 FROM cc_contacttype a
5634 LEFT JOIN cc_language lang on lang.isactive = 'Y'
5635 LEFT JOIN cc_contacttypelang al on al.language_id = lang.id and al.contacttype_id = a.id;
5636
5637-- PARTY CERTIFICATION TYPE ;
5638-- ##############################################################################################
5639CREATE OR REPLACE VIEW cc_partycertificationtypeview AS
5640 select a.id, a.code, a.ismandatory, lang.id as language_id, al.name as name, a.certificationclass
5641 FROM cc_partycertificationtype a
5642 LEFT JOIN cc_language lang on lang.isactive = 'Y'
5643 LEFT JOIN cc_partycertificationtypelang al on al.language_id = lang.id and al.partycertificationtype_id = a.id;
5644
5645-- PARTY CERTIFICATION TYPE;
5646-- ##############################################################################################
5647CREATE OR REPLACE VIEW cc_partycertificationview AS
5648 select pc.id as id, pc.party_id, pc.partycertificationtype_id, pct.ismandatory, lang.id as language_id, pcl.name as
5649 name
5650 FROM cc_partycertification pc
5651 LEFT JOIN cc_language lang on lang.isactive = 'Y'
5652 LEFT JOIN cc_partycertificationtype pct on pct.id = pc.partycertificationtype_id
5653 LEFT JOIN cc_partycertificationtypelang pcl on pcl.language_id = lang.id and pcl.partycertificationtype_id = pc.partycertificationtype_id;
5654
5655-- SHIPMENT ENTRIES;
5656-- ##############################################################################################
5657CREATE OR REPLACE VIEW cc_shipmententryview AS
5658 select f.delegation_id, lang.id as language_id, c.id, c.shipment_id, shp.file_id, shp.name AS shipmentname, f.name as filename, COALESCE(col.name, COALESCE(co.name, COALESCE(ao.name, COALESCE(pol.name, po.name)))) as originname, COALESCE(cdl.name, COALESCE(cd.name, COALESCE(ad.name, COALESCE(pdl.name, pd.name)))) as destinationname
5659 , COALESCE(couol.name, couo.name) as countryoriginname, COALESCE(coudl.name, coud.name) as countrydestinationname
5660 , ftr.transportmode, ftr.trafficflow, ftr.trafficchargetype, ftr.etd, ftr.eta, ftr.origin_id, ftr.destination_id
5661 , ftr.airportorigin_id, ftr.airportdestination_id
5662 , COALESCE(po.country_id, COALESCE(ao.country_id, ftr.countryorigin_id)) as countryorigin_id
5663 , COALESCE(pd.country_id, COALESCE(ad.country_id, ftr.destination_id)) as countrydestination_id
5664 , c.packages, c.packagetype_id, pkl.name as packagetypename, c.grossweight, c.netweight, c.volume, c.description, c.marks, e.id as entry_id, e.entrynumber, e.entrydate, e.remarks, sat.absolutefilepath as filepath
5665 , ftr.warehouse_id, COALESCE(pwa.name, COALESCE(pw.name_short, pw.name)) as warehousename, f.status as filestatus
5666 , COALESCE(shipp.name_short, shipp.name) as shippername, COALESCE(consp.name_short, consp.name) as consigneename, e.shipmentattachment_id
5667 from cc_shipmentcomm c
5668 LEFT JOIN cc_language lang on lang.isactive = 'Y'
5669 LEFT JOIN cc_shipmententry e on e.id = c.shipmententry_id
5670 LEFT JOIN cc_shipment shp on shp.id = c.shipment_id
5671 LEFT JOIN cc_shipmenttraffic sht on sht.shipment_id = shp.id
5672 LEFT JOIN cc_filetraffic ftr on ftr.file_id = shp.file_id
5673 LEFT JOIN cc_file f on f.id = shp.file_id
5674 LEFT JOIN cc_unlocodelang pol on pol.unlocode_id = ftr.origin_id and pol.language_id = lang.id
5675 LEFT JOIN cc_unlocode po on po.id = ftr.origin_id
5676 LEFT JOIN cc_unlocodelang pdl on pdl.unlocode_id = ftr.destination_id and pdl.language_id = lang.id
5677 LEFT JOIN cc_unlocode pd on pd.id = ftr.destination_id
5678 LEFT JOIN cc_airport ao on ao.id = ftr.airportorigin_id
5679 LEFT JOIN cc_airport ad on ad.id = ftr.airportdestination_id
5680 LEFT JOIN cc_countrylang col on col.country_id = ftr.countryorigin_id and col.language_id = lang.id
5681 LEFT JOIN cc_country co on co.id = ftr.countryorigin_id
5682 LEFT JOIN cc_countrylang cdl on cdl.country_id = ftr.countrydestination_id and cdl.language_id = lang.id
5683 LEFT JOIN cc_country cd on cd.id = ftr.countrydestination_id
5684 LEFT JOIN cc_countrylang couol on couol.country_id = COALESCE(po.country_id, COALESCE(ao.country_id, ftr.countryorigin_id)) and couol.language_id = lang.id
5685 LEFT JOIN cc_country couo on couo.id = COALESCE(po.country_id, COALESCE(ao.country_id, ftr.countryorigin_id))
5686 LEFT JOIN cc_countrylang coudl on coudl.country_id = COALESCE(pd.country_id, COALESCE(ad.country_id, ftr.countrydestination_id)) and coudl.language_id = lang.id
5687 LEFT JOIN cc_country coud on coud.id = COALESCE(pd.country_id, COALESCE(ad.country_id, ftr.countrydestination_id))
5688 LEFT JOIN cc_packagetypelang pkl on pkl.packagetype_id = c.packagetype_id and pkl.language_id = lang.id
5689 LEFT JOIN cc_shipmentattachment sat on sat.id = e.shipmentattachment_id
5690 LEFT JOIN cc_partyaddress pwa on pwa.id = ftr.warehouse_id
5691 LEFT JOIN cc_party pw on pw.id = pwa.party_id
5692 LEFT JOIN cc_partyaddress shippa on shippa.id = sht.shipper_id
5693 LEFT JOIN cc_party shipp on shipp.id = shippa.party_id
5694 LEFT JOIN cc_partyaddress conspa on conspa.id = sht.consignee_id
5695 LEFT JOIN cc_party consp on consp.id = conspa.party_id
5696 where f.filetype = 'TRA';
5697
5698
5699-- CONTAINER BLANKET TYPE;
5700-- ##############################################################################################
5701CREATE OR REPLACE VIEW cc_containerblankettypeview AS
5702
5703 SELECT cb.id, cbl.language_id, cbl.name
5704
5705 FROM cc_containerblankettype cb
5706 LEFT JOIN cc_language lang on lang.isactive = 'Y'
5707 LEFT JOIN cc_containerblankettypelang cbl on cbl.containerblankettype_id = cb.id and cbl.language_id = lang.id;
5708
5709-- BL PAYMENT TYPE ID ;
5710-- ##############################################################################################
5711 CREATE OR REPLACE VIEW cc_blpaymenttypeview AS
5712 select b.id, lang.id as language_id, bl.name as name
5713 FROM cc_blpaymenttype b
5714 LEFT JOIN cc_language lang on lang.isactive = 'Y'
5715 LEFT JOIN cc_blpaymenttypelang bl on bl.language_id = lang.id and bl.blpaymenttype_id = b.id;
5716
5717-- TARIFFS BY CUSTOMERS ;
5718-- ##############################################################################################
5719CREATE OR REPLACE VIEW cc_customertariffsaleview AS
5720 select p.id, p.company_id, p.fiscaladdress_id, COALESCE(p.name_short, p.name) as name
5721 , c.saletariffheaderseafclexport_id
5722 , c.saletariffheadersealclexport_id
5723 , c.saletariffheaderseafclimport_id
5724 , c.saletariffheadersealclimport_id
5725 , c.saletariffheaderairimport_id
5726 , c.saletariffheaderairexport_id
5727 , c.saletariffheadertirimport_id
5728 , c.saletariffheadertirexport_id
5729 , c.saletariffheadercourierimport_id
5730 , c.saletariffheadercourierexport_id
5731 , c.saletariffheaderrailfclexport_id
5732 , c.saletariffheaderraillclexport_id
5733 , c.saletariffheaderrailfclimport_id
5734 , c.saletariffheaderraillclimport_id
5735 , c.saletariffcustomsimport_id
5736 , c.saletariffcustomsexport_id
5737 , c.saletariffwarehouse_id
5738 FROM cc_customer c
5739 LEFT JOIN cc_party p on p.id = c.party_id;
5740-- SQL SENTENCES ;
5741-- ##############################################################################################
5742 CREATE OR REPLACE VIEW cc_sqlsentenceview as
5743
5744 select s.id, s.sentence, s.success, s.error, s.createdby_id, us.name as createdbyusername, s.createddate
5745 FROM cc_sqlsentence s
5746 LEFT JOIN cc_useraccess us on us.id = s.createdby_id;
5747
5748-- PARTY SALE TARIFFS ;
5749-- ##############################################################################################
5750 CREATE OR REPLACE VIEW cc_partysaletariffview AS
5751 SELECT
5752
5753 p.company_id
5754 , p.fiscaladdress_id as id
5755 , COALESCE(p.name, name_short) as name
5756 , c.saletariffheaderseafclexport_id
5757 , c.saletariffheadersealclexport_id
5758 , c.saletariffheaderseafclimport_id
5759 , c.saletariffheadersealclimport_id
5760 , c.saletariffheaderairimport_id
5761 , c.saletariffheaderairexport_id
5762 , c.saletariffheadertirimport_id
5763 , c.saletariffheadertirexport_id
5764 , c.saletariffheadercourierimport_id
5765 , c.saletariffheadercourierexport_id
5766 , c.saletariffheaderrailfclexport_id
5767 , c.saletariffheaderraillclexport_id
5768 , c.saletariffheaderrailfclimport_id
5769 , c.saletariffheaderraillclimport_id
5770 , c.saletariffcustomsimport_id
5771 , c.saletariffcustomsexport_id
5772 , c.saletariffwarehouse_id
5773
5774 FROM cc_customer c
5775 LEFT JOIN cc_party p on p.id = c.party_id;
5776
5777-- PROCESSES ;
5778-- ##############################################################################################
5779 CREATE OR REPLACE VIEW cc_processheaderview
5780
5781 AS SELECT p.id, p.datestart, p.dateend, p.status, p.errormessage, p.createddate, p.user_id, u.name as username
5782
5783 FROM cc_processheader p
5784 LEFT JOIN cc_useraccess u on u.id = p.user_id;