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