-
Notifications
You must be signed in to change notification settings - Fork 0
/
keu_slave_3tutupbulan_unittenggala_12112015.php
1639 lines (1502 loc) · 70.1 KB
/
keu_slave_3tutupbulan_unittenggala_12112015.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
require_once('master_validation.php');
include_once('lib/nangkoelib.php');
include_once('lib/zLib.php');
include_once('lib/zPosting.php');
include_once('lib/zJournal.php');
$param = $_POST;
$tmpPeriod = explode('-',$param['periode']);
$tahunbulan = implode("",$tmpPeriod);
$tahun = $tmpPeriod[0];
$bulan = $tmpPeriod[1];
$proses = $_GET['proses'];
//cek apakah ada data
/*$str="select nojurnal FROM ".$dbname.".keu_jurnalht where tanggal like '".$param['periode']."%'
and nojurnal like '%".$_SESSION['empl']['lokasitugas']."/KBN%'";
//exit(" Error".$str);
$res=mysql_query($str);
if(mysql_num_rows($res)>0){
exit(" Warning: Proses Gaji sudah dilakukan");
}else{
//$str="insert into ".$dbname.".keu_jurnalht(nojurnal,kodejurnal,tanggal,tanggalentry,posting,totaldebet,totalkredit,amountkoreksi,noreferensi,autojurnal,matauang,kurs,revisi) values(
// '".$tahunbulan."28/".$_SESSION['empl']['lokasitugas']."/KBNB0/0000','KBNB0','".$param['periode']."-28','".date('Y-m-d')."','1','0','0','0','ALK_GAJI','1','IDR','1','0')";
//mysql_query($str);
}*/
//ambil akun laba tahun berjalan;
$stl="select noakundebet from ".$dbname.".keu_5parameterjurnal where jurnalid='CLM'";
$rel=mysql_query($stl);
$akunCLM='';
while($bal=mysql_fetch_object($rel))
{
$akunCLM=$bal->noakundebet;
}
//ambil akun laba ditahan
$stl="select noakundebet from ".$dbname.".keu_5parameterjurnal where jurnalid='CLY'";
$rel=mysql_query($stl);
$akunCLY='';
while($bal=mysql_fetch_object($rel))
{
$akunCLY=$bal->noakundebet;
}
//ambil batas bawah akun laba/rugi
$stl="select noakundebet from ".$dbname.".keu_5parameterjurnal where jurnalid='RAT'";
$rel=mysql_query($stl);
$akunRAT='';
while($bal=mysql_fetch_object($rel))
{
$akunRAT=$bal->noakundebet;
}
if($akunCLM=='' or $akunCLY=='' or $akunRAT=='')
{
if($_SESSION['language']=='EN'){
exit(' Error: Annual income account data, account retained earnings and account limits profits / losses not yet listed on the parameters of the journal');
}else{
exit(' Error: data akun laba tahunan, akun laba ditahan dan batas akun laba/rugi belum terdaftar pada parameter jurnal');
}
}
#periksa apakah sudah diposting semua transaksi kas dan bappp
$str="select tanggalmulai,tanggalsampai from ".$dbname.".setup_periodeakuntansi where
periode='".$param['periode']."' and kodeorg='".$_SESSION['empl']['lokasitugas']."'";
//echo $str."____";
$res=mysql_query($str);
$currstart='';
$currend='';
while($bar=mysql_fetch_object($res))
{
$currstart=$bar->tanggalmulai;
$currend=$bar->tanggalsampai;
}
if($currstart=='' or $currend=='')
{
exit('Error: Accounting period is not normal to '.$_SESSION['empl']['lokasitugas']);
}
else
{
#periksa kas
$str="select notransaksi,tanggal,jumlah from ".$dbname.".keu_kasbankht where kodeorg='".$_SESSION['empl']['lokasitugas']."'
and tanggal between '".$currstart."' and '".$currend."' and posting=0";
$res=mysql_query($str);
if(mysql_num_rows($res)>0)
{
echo " There are Cash/Bank transaction that has not been posted:\n";
$no=0;
while($bar=mysql_fetch_object($res))
{
$no+=1;
echo $no.". No ".$bar->notransaksi.":".tanggalnormal($bar->tanggal)."->Rp. ".number_format($bar->jumlah,0)."\n";
}
exit('Error');
}
#periksa bapp
$str="select notransaksi,tanggal,jumlahrealisasi from ".$dbname.".log_baspk where kodeblok like '".$_SESSION['empl']['lokasitugas']."%'
and tanggal between '".$currstart."' and '".$currend."' and statusjurnal=0";
$res=mysql_query($str);
if(mysql_num_rows($res)>0)
{
echo "There are Contract Realization transaction that has not been posted:\n";
$no=0;
while($bar=mysql_fetch_object($res))
{
$no+=1;
echo $no.". No ".$bar->notransaksi.":".tanggalnormal($bar->tanggal)."->Rp. ".number_format($bar->jumlahrealisasi,0)."\n";
}
exit('Error');
}
#periksa jurnal tidak balance
$str="select nojurnal,tanggal,debet,kredit from ".$dbname.".keu_jurnal_tidak_balance_vw where kodeorg = '".$_SESSION['empl']['lokasitugas']."'
and tanggal between '".$currstart."' and '".$currend."'
and nojurnal not like '%/CLSM/%'";
$res=mysql_query($str);
if(mysql_num_rows($res)>0)
{
echo "There is still yet balanced Journal:\n";
$no=0;
while($bar=mysql_fetch_object($res))
{
$no+=1;
echo $no.". No ".$bar->nojurnal.":".tanggalnormal($bar->tanggal)."->(D)Rp. ".number_format($bar->debet,0).":(K)Rp. ".number_format($bar->kredit,0)."\n";
}
exit('Error');
}
#periksa gudang
$str="select notransaksi,tanggal, kodegudang from ".$dbname.".log_transaksiht where post=0 and kodegudang like '".$_SESSION['empl']['lokasitugas']."%'
and tanggal between '".$currstart."' and '".$currend."'";
$res=mysql_query($str);
$stm='';
if(mysql_num_rows($res)>0){
while($bar=mysql_fetch_object($res))
{
$stm.="Gudang:".$bar->kodegudang."->No.>".$bar->notransaksi."->".$bar->tanggal."<br>";
}
echo "Error: Warehouse transaction that has not been posted\r<br>".$stm;
exit();
}
/*
#cek penerimaan barang mutasi tambahan jamhari 23062013
$scekMut="select * from ".$dbname.".log_transaksiht where kodegudang like '".$_SESSION['empl']['lokasitugas']."%'
and tanggal between '".$currstart."' and '".$currend."' and tipetransaksi=7
and (notransaksireferensi is null or notransaksireferensi='') order by notransaksi asc";
//exit("error:".$scekMut);
$qcekMut=mysql_query($scekMut) or die(mysql_error($conn));
if(mysql_num_rows($qcekMut)>0)
{
echo "Error: Still no receipt of goods mutation that has not been done:\n";
while($rcekMut= mysql_fetch_object($qcekMut)){
echo $rcekMut->notransaksi.":".tanggalnormal($rcekMut->tanggal)."\n";
}
exit("error");
}
#Periksa BKM
$str="select notransaksi,tanggal from ".$dbname.".kebun_aktifitas where kodeorg='".$_SESSION['empl']['lokasitugas']."'
and tanggal between '".$currstart."' and '".$currend."' and jurnal=0";
$res=mysql_query($str);
if(mysql_num_rows($res)>0)
{
echo " There still estate transaction that has not been posted:\n";
$no=0;
while($bar=mysql_fetch_object($res))
{
$no+=1;
echo $no.". No ".$bar->notransaksi.":".tanggalnormal($bar->tanggal)."\n";
}
exit('Error');
}
*/
#Periksa TRAKSI
$str="select notransaksi,tanggal from ".$dbname.".vhc_runht where kodeorg='".$_SESSION['empl']['lokasitugas']."'
and tanggal between '".$currstart."' and '".$currend."' and posting=0";
$res=mysql_query($str);
if(mysql_num_rows($res)>0)
{
echo " There still Vehicle Runn transaction that has not been posted:\n";
$no=0;
while($bar=mysql_fetch_object($res))
{
$no+=1;
echo $no.". No ".$bar->notransaksi.":".tanggalnormal($bar->tanggal)."\n";
}
exit('Error');
}
}
#PERIKSA akun transit yang belum nol=============================
$str="select sum(debet)-sum(kredit) as saldo FROM ".$dbname.".keu_jurnalsum_vw where periode ='".$param['periode']."'
and kodeorg='".$_SESSION['empl']['lokasitugas']."' AND noakun like '4%'";
$res=mysql_query($str);
$transit=0;
if(mysql_num_rows($res)>0){
while($bar=mysql_fetch_object($res))
{
$transit=$bar->saldo;
}
}
if($transit>10 && $transit!='')#lebih dari 10 rupiah
{
exit(" Error: Transit account has not been allocated correctly, remains:".$transit);
}
#---------------------------------------==================================
if(substr($_SESSION['empl']['lokasitugas'],2,2)!='HO' and substr($_SESSION['empl']['lokasitugas'],2,2)!='LO'){
#PERIKSA apakah sudah ada gaji=============================
//$str="select jumlah FROM ".$dbname.".sdm_gaji where periodegaji ='".$param['periode']."'
// and kodeorg='".$_SESSION['empl']['lokasitugas']."' and substr(kodeorg,3,2)!='HO'";
//$str="select nojurnal FROM ".$dbname.".keu_jurnalht where tanggal like '".$param['periode']."%'
// and nojurnal like '%".$_SESSION['empl']['lokasitugas']."/KBN%' and substr(nojurnal,12,2)!='HO'";
$str="select nojurnal FROM ".$dbname.".keu_jurnalht where tanggal like '".$param['periode']."%'
and nojurnal like '%".$_SESSION['empl']['lokasitugas']."/KBN%'";
$res=mysql_query($str);
if(mysql_num_rows($res)>0){
}else{
exit(" Error: Proses Gaji has not been processed. ");
}
#---------------------------------------==================================
}
/**************************************************************
* [START] Cek Pengakuan Penjualan ****************************
**************************************************************/
if($_SESSION['empl']['tipelokasitugas']=='HOLDING'){
$listTiket="";
/*$qJual = "SELECT notransaksi,a.nokontrak
FROM ".$dbname.".pabrik_timbangan a
INNER JOIN ".$dbname.".pmn_kontrakjual d on a.nokontrak = d.nokontrak
WHERE date(a.tanggal) between '".$currstart."' and '".$currend.
"'and a.millcode in (select kodeorganisasi from ".$dbname.".organisasi where induk='".$_SESSION['org']['kodeorganisasi']."' and tipe='PABRIK')";*/
$qJual = "SELECT notransaksi,a.nokontrak
FROM ".$dbname.".pabrik_timbangan a
INNER JOIN ".$dbname.".pmn_kontrakjual d on a.nokontrak = d.nokontrak
WHERE date(a.tanggal) between '".$currstart."' and '".$currend.
"'and a.nokontrak in (select nokontrak from ".$dbname.".pmn_kontrakjual where tanggalkontrak like '".substr($currstart,0,4)."%')
and a.millcode in (select kodeorganisasi from ".$dbname.".organisasi where induk='".$_SESSION['org']['kodeorganisasi']."' and tipe='PABRIK')";
$resJual = fetchData($qJual);
if(!empty($resJual)) {
$listTiket = '';
foreach($resJual as $row) {
$scek2="select notransaksi,posting,tanggalpengakuan from ".$dbname.".keu_pengakuanjual
where notransaksi='".$row['notransaksi']."'";
//exit("error:".$scek2);
$qcek2=mysql_query($scek2) or die(mysql_error($conn));
$rcek2=mysql_num_rows($qcek2);
if($rcek2==0){
$listTiket .= "- ".$row['notransaksi']."\n";
}
}
if($listTiket!=''){
exit("Warning: Ada Timbangan Pabrik ke Eksternal yang belum diakui\n".$listTiket);
}
}
}
/**************************************************************
* [END] Cek Pengakuan Penjualan ******************************
**************************************************************/
/**************************************************************
* [START] Buat HPP CPO,PK,TBS ********************************
**************************************************************/
$tglPeriode="tanggal between '".$currstart."' and '".$currend."' ";
$tglPeriode2="left(tanggal,10) between '".$currstart."' and '".$currend."' ";
$ptUnit=$_SESSION['org']['kodeorganisasi'];
#cek apakah memiliki pabrik
#jika memiliki pabrik,cek apakah sudah akrtif mengolah jika iya,masuk ke dalam proses hpp. jika tidak, tidak masuk ke proses hpp
$sCekPabrikA="select count(kodeorganisasi) as jmlhPabrik from ".$dbname.".organisasi where tipe='PABRIK' and induk='".$ptUnit."' ";
$qCekPabrikA=mysql_query($sCekPabrikA) or die(mysql_error($conn));
$rCekPabrikA=mysql_fetch_assoc($qCekPabrikA);
if($rCekPabrikA!=0){
$sCekPabrik="select count(kodeorg) as jmlhPabrik from ".$dbname.".pabrik_produksi
where kodeorg in (select kodeorganisasi from ".$dbname.".organisasi where tipe='PABRIK' and induk='".$ptUnit."') and ".$tglPeriode."";
$qCekPabrik=mysql_query($sCekPabrik) or die(mysql_error($conn));
$rCekPabrik=mysql_fetch_assoc($qCekPabrik);
if(intval($rCekPabrik['jmlhPabrik'])!=0){//start pengecekan ada pabrik atau tidak
$ptUnit = $_SESSION['org']['kodeorganisasi'];
$unit = $_SESSION['empl']['lokasitugas'];
if(substr($_SESSION['empl']['lokasitugas'],2,2)=='HO'){
// Kode Barang
$barang = array(
'cpo' => '40000001',
'pk' => '40000002',
'tbs' => '40000003',
);
// Cek Saldo Awal HPP
$qHpp = selectQuery($dbname,'keu_4hpp',"*",
"kodeorg = '".$unit."' and periode = '".$param['periode']."'");
$resHpp = fetchData($qHpp);
$optHpp = array();
foreach($resHpp as $row) {
$optHpp[$row['kodebarang']] = array(
'qty' => $row['qtyawal'],
'rp' => $row['rpawal']
);
}
// Init Saldo Awal
$tbsAwal = (empty($resHpp))? 0: $optHpp[$barang['tbs']]['qty'];
$tbsRpAwal = (empty($resHpp))? 0: $optHpp[$barang['tbs']]['rp'];
$cpoAwal = (empty($resHpp))? 0: $optHpp[$barang['cpo']]['qty'];
$cpoRpAwal = (empty($resHpp))? 0: $optHpp[$barang['cpo']]['rp'];
$pkAwal = (empty($resHpp))? 0: $optHpp[$barang['pk']]['qty'];
$pkRpAwal = (empty($resHpp))? 0: $optHpp[$barang['pk']]['rp'];
// Price / KG
@$priceTbsAwal = empty($tbsAwal)? 0: $tbsRpAwal / $tbsAwal;
@$tbsAwalAlkCpo=$tbsRpAwal*0.9;
@$tbsAwalAlkKer=$tbsRpAwal*0.1;
/**
* TBS - Penerimaan
*/
// Fisik
// $qTbsIn = "select intex,sum(beratbersih-kgpotsortasi) as tbs from ".$dbname.".pabrik_timbangan
// where kodebarang='40000003' and left(tanggal,10) between '".$currstart."' and '".$currend."'
// and millcode in (select kodeorganisasi from ".$dbname.".organisasi where tipe='PABRIK' and induk='".$ptUnit."')";
// $resTbsIn = fetchData($qTbsIn);
// //$tbsIn = array();
// foreach($resTbsIn as $row) {
// $tbsIn = $row['tbs'];
// }
$qTbsIn = "select sum(tbsmasuk) as tbsolah from ".$dbname.".pabrik_produksi
where kodeorg in (select kodeorganisasi from ".$dbname.".organisasi where tipe='PABRIK' and induk='".$ptUnit."')
and ".$tglPeriode."";
$resTbsIn = fetchData($qTbsIn);
$tbsIn = empty($resTbsIn[0]['tbsolah'])? 0: $resTbsIn[0]['tbsolah'];
// Rupiah Internal
$qTbsRpPanen = "select sum(jumlah) as jumlah from ".$dbname.".keu_jurnaldt_vw
where ".$tglPeriode." and kodeorg in (select kodeorganisasi from ".$dbname.".organisasi
where induk='".$ptUnit."') and noakun like '61%'
and noakun not in ('6219999','6430800','6430500', '6430600', '6430700') and nojurnal not like '%HPP%' ";
$resTbsRp = fetchData($qTbsRpPanen);
$rpTbsInt = empty($resTbsRp[0]['jumlah'])? 0: $resTbsRp[0]['jumlah'];
#biaya deplesi
$sDeplesi="select sum(jumlah) as deplesi from ".$dbname.".keu_jurnaldt
where ".$tglPeriode." and noakun='7150201' and kodeorg='".$unit."'";
$qDeplesi=mysql_query($sDeplesi) or die(mysql_error($conn));
$rDeplesi=mysql_fetch_assoc($qDeplesi);
$rpTbsInt=$rpTbsInt+$rDeplesi['deplesi'];
#rupiah biaya jika ada jurnal memorial dari HO
$qTbsRpRawat = "select sum(jumlah) as jumlah from ".$dbname.".keu_jurnaldt_vw
where ".$tglPeriode." and kodeorg in (select kodeorganisasi from ".$dbname.".organisasi where induk='".$ptUnit."')
and noakun like '62%' and noakun not in ('6219999','6430800','6430500', '6430600', '6430700') and nojurnal not like '%HPP%'";
//echo $qTbsRpRawat;
$resTbsRp2 = fetchData($qTbsRpRawat);
$rpTbsInt2 = empty($resTbsRp2[0]['jumlah'])? 0: $resTbsRp2[0]['jumlah'];
#rupiah biaya tbs beli ke plasma
$qTbsRpRawat = "select sum(jumlah) as jumlah from ".$dbname.".keu_jurnaldt_vw
where ".$tglPeriode." and kodeorg in (select kodeorganisasi from ".$dbname.".organisasi where induk='".$ptUnit."')
and noakun in ('6410400','6410100') and noakun not in ('6219999','6430800','6430500', '6430600', '6430700') and nojurnal not like '%HPP%'";
//echo $qTbsRpRawat;
$resTbsRp3 = fetchData($qTbsRpRawat);
$rpTbsInt3 = empty($resTbsRp3[0]['jumlah'])? 0: $resTbsRp3[0]['jumlah'];
#overhead
#total unit kebun
/*$sUnitKbn="select distinct kodeorg from ".$dbname.".keu_jurnaldt
where ".$tglPeriode." and kodeorg in (select distinct kodeorganisasi from ".$dbname.".organisasi where tipe not in ('HOLDING','KANWIL') and tipe='KEBUN' and induk='".$ptUnit."') order by kodeorg asc ";*/
$sUnitKbn="select distinct unit from ".$dbname.".kebun_prestasi_vw
where ".$tglPeriode." and unit in (select distinct kodeorganisasi from ".$dbname.".organisasi where tipe='KEBUN' and induk='".$ptUnit."') order by unit asc";
$qUnitKbn=mysql_query($sUnitKbn) or die(mysql_error($conn));
$rowUnitKbn=mysql_num_rows($qUnitKbn);
#total unit pabrik
$sUnitPbrk="select distinct kodeorg from ".$dbname.".pabrik_pengolahan
where ".$tglPeriode." and kodeorg in (select distinct kodeorganisasi from ".$dbname.".organisasi where tipe='PABRIK' and induk='".$ptUnit."') order by kodeorg asc ";
$qUnitPbrk=mysql_query($sUnitPbrk) or die(mysql_error($conn));
$rowUnitPbrk=mysql_num_rows($qUnitPbrk);
$rowUnit=$rowUnitKbn+$rowUnitPbrk;
#over head ro dan ho
$sOverHead="select sum(jumlah) as overhead from ".$dbname.".keu_jurnaldt
where ".$tglPeriode." and noakun like '7%' and noakun!='7150201' and kodeorg in (select distinct kodeorganisasi from ".$dbname.".organisasi where tipe in ('HOLDING','KANWIL') and induk='".$ptUnit."') and noakun!='7199999'";
$qOverHead=mysql_query($sOverHead) or die(mysql_error($conn));
$rOverHead=mysql_fetch_assoc($qOverHead);
@$byOverHead=$rOverHead['overhead']/$rowUnit;
#overh head kebun
$sOverHeadKbn="select sum(jumlah) as overhead from ".$dbname.".keu_jurnaldt
where ".$tglPeriode." and noakun like '7%' and kodeorg in (select distinct kodeorganisasi from ".$dbname.".organisasi where tipe='KEBUN' and induk='".$ptUnit."') and noakun!='7199999'";
$qOverHeadKbn=mysql_query($sOverHeadKbn) or die(mysql_error($conn));
$rOverHeadKbn=mysql_fetch_assoc($qOverHeadKbn);
$byOvHeadKbn=($byOverHead*$rowUnitKbn)+$rOverHeadKbn['overhead'];#rupiah untuk jurnal alokasi overhead
$rpTbsInt=$rpTbsInt+$rpTbsInt2+$rpTbsInt3;
// Rupiah Eksternal
$qTbsEks = "select sum(jumlah) as jumlah from ".$dbname.".keu_jurnaldt_vw
where ".$tglPeriode." and kodeorg = '".$unit."' and noakun in ('6430800','6410300')";
$resTbsRpEks = fetchData($qTbsEks);
$rpTbsEks = empty($resTbsRpEks[0]['jumlah'])? 0: $resTbsRpEks[0]['jumlah'];
// Rupiah Afiliasi
$qTbsAf = "select sum(jumlah) as jumlah from ".$dbname.".keu_jurnaldt_vw
where ".$tglPeriode." and kodeorg = '".$unit."'
and noakun in ('6430500', '6430600', '6430700','6410200')";
$resTbsRpAf = fetchData($qTbsAf);
$rpTbsAf = empty($resTbsRpAf[0]['jumlah'])? 0: $resTbsRpAf[0]['jumlah'];
// Price Mutasi
$sumTbsIn = $tbsIn;
@$priceTbsMutasi = empty($sumTbsIn)? 0: ($rpTbsInt+$rpTbsEks+$rpTbsAf+$byOvHeadKbn) / $sumTbsIn;
#total biaya tbs
$totByTbs=$rpTbsInt + $rpTbsEks + $rpTbsAf+$byOvHeadKbn;
//exit("warning:".$totByTbs."___".$rpTbsInt."___".$rpTbsEks."___".$rpTbsAf);
/**
* TBS - Pengeluaran
*/
// Fisik
$qTbsOut = "select sum(tbsdiolah) as tbsolah from ".$dbname.".pabrik_produksi
where kodeorg in (select kodeorganisasi from ".$dbname.".organisasi where tipe='PABRIK' and induk='".$ptUnit."')
and ".$tglPeriode."";
$resTbsOut = fetchData($qTbsOut);
$tbsOut = empty($resTbsOut[0]['tbsolah'])? 0: $resTbsOut[0]['tbsolah'];
// Rupiah
$sisaTbsOut = $tbsOut - $tbsAwal; // Cari TBS yang memakai rupiah rata2 mutasi
$qtyTbs1 = ($sisaTbsOut > 0)?$tbsAwal : $tbsOut; // Qty TBS yang memakai harga awal
$rpTbsOut = $qtyTbs1 * $priceTbsAwal; // Rupiah dari TBS yang memakai harga awal
//exit("error:".$tbsOut."___".$tbsAwal."___".$qtyTbs1);
if($sisaTbsOut > 0) {
$rpTbsOut += $sisaTbsOut * $priceTbsMutasi;
}
/**
* TBS - Saldo Akhir
*/
$tbsQtyAkhir = $tbsAwal + $tbsIn - $tbsOut;
$tbsRpAkhir = $tbsRpAwal+($rpTbsInt + $rpTbsEks + $rpTbsAf+$byOvHeadKbn) - $rpTbsOut;
// Price
@$cpoPriceAwal = empty($cpoAwal)? 0: $cpoRpAwal / $cpoAwal;
@$pkPriceAwal = empty($pkAwal)? 0: $pkRpAwal / $pkAwal;
/**
* CPO & PK - Penerimaan
*/
// Fisik
$qCpoOlah = "SELECT sum(oer) as cpoqty, sum(oerpk) as pkqty
FROM ".$dbname.".pabrik_produksi WHERE ".$tglPeriode."
AND kodeorg in (select kodeorganisasi from ".$dbname.".organisasi
where tipe='PABRIK' and induk='".$ptUnit."')";
$resCpoOlah = fetchData($qCpoOlah);
$cpoIn = empty($resCpoOlah[0]['cpoqty'])? 0: $resCpoOlah[0]['cpoqty'];
$pkIn = empty($resCpoOlah[0]['pkqty'])? 0: $resCpoOlah[0]['pkqty'];
// // Rupiah Pengolahan
$cpoRpOlah = (($totByTbs * 0.9)+$tbsAwalAlkCpo)-($tbsRpAkhir*0.9);//perubahan total biaya di tambah rupiah awal di kurang tbs di olah
$pkRpOlah = (($totByTbs * 0.1)+$tbsAwalAlkKer)-($tbsRpAkhir*0.1);
// Rupiah Biaya Pabrik
$qCpoRp = "select sum(jumlah) as jumlah from ".$dbname.".keu_jurnaldt_vw
where ".$tglPeriode." and kodeorg in (select kodeorganisasi from ".$dbname.".organisasi
where tipe='PABRIK' and induk='".$ptUnit."') and noakun like '63%'";
$resCpoRp = fetchData($qCpoRp);
$cpoRpInt = empty($resCpoRp[0]['jumlah'])? 0: $resCpoRp[0]['jumlah'] * 0.9;
$pkRpInt = empty($resCpoRp[0]['jumlah'])? 0: $resCpoRp[0]['jumlah'] * 0.1;
// Rupiah Eksternal
$qCpoEks = "select sum(jumlah) as jumlah from ".$dbname.".keu_jurnaldt_vw
where ".$tglPeriode." and kodeorg = '".$unit."' and noakun like '6420500'";
$resCpoRpEks = fetchData($qCpoEks);
$cpoRpEks = empty($resCpoRpEks[0]['jumlah'])? 0: $resCpoRpEks[0]['jumlah'] * 0.9;
$pkRpEks = empty($resCpoRpEks[0]['jumlah'])? 0: $resCpoRpEks[0]['jumlah'] * 0.1;
// Rupiah Afiliasi
$qCpoAf = "select sum(jumlah) as jumlah from ".$dbname.".keu_jurnaldt_vw
where ".$tglPeriode." and kodeorg = '".$unit."'
and noakun in ('6420100', '6420200', '6420300','6420400')";
$resCpoRpAf = fetchData($qCpoAf);
$cpoRpAf = empty($resCpoRpAf[0]['jumlah'])? 0: $resCpoRpAf[0]['jumlah'] * 0.9;
$pkRpAf = empty($resCpoRpAf[0]['jumlah'])? 0: $resCpoRpAf[0]['jumlah'] * 0.1;
//over head pabrik
$sOverHeadMll="select sum(jumlah) as overhead from ".$dbname.".keu_jurnaldt
where ".$tglPeriode." and noakun like '7%' and kodeorg in (select distinct kodeorganisasi from ".$dbname.".organisasi where tipe='PABRIK' and induk='".$ptUnit."') and noakun!='7199999'";
$qOverHeadMll=mysql_query($sOverHeadMll) or die(mysql_error($conn));
$rOverHeadMll=mysql_fetch_assoc($qOverHeadMll);
$byOvHeadMll=($byOverHead*$rowUnitPbrk)+$rOverHeadMll['overhead'];
$cpoOverhead=$byOvHeadMll*0.9;#rupiah untuk jurnal alokasi overhead untuk cpo
$kerOverhead=$byOvHeadMll*0.1;#rupiah untuk jurnal alokasi overhead untuk ker
// Price
@$cpoPriceMutasi = empty($cpoIn)? 0: ($cpoRpOlah + $cpoRpInt + $cpoRpEks + $cpoRpAf+$cpoOverhead) / $cpoIn;
@$pkPriceMutasi = empty($pkIn)? 0: ($pkRpOlah + $pkRpInt + $pkRpEks + $pkRpAf+$kerOverhead)/ $pkIn;
//exit("error:".$cpoRpOlah."+".$cpoRpInt."+".$cpoRpEks."+".$cpoRpAf."+".$cpoOverhead."___".$cpoIn);
/**
* CPO & PK - Pengeluaran
*/
// Fisik
$qCpoOut = "select kodebarang,sum(beratbersih) as kg from ".$dbname.".pabrik_timbangan
where millcode in (select kodeorganisasi from ".$dbname.".organisasi where tipe='PABRIK' and induk='".$ptUnit."')
and ".$tglPeriode2." and kodebarang in ('40000001','40000002') and char_length(notransaksi)<11 group by kodebarang";
$resCpoOut = fetchData($qCpoOut);
$optCpoOut = array();
foreach($resCpoOut as $row) {
$optCpoOut[$row['kodebarang']] = $row['kg'];
}
$cpoOut = isset($optCpoOut['40000001'])? $optCpoOut['40000001']: 0;
$pkOut = isset($optCpoOut['40000002'])? $optCpoOut['40000002']: 0;
// Rupiah
$sisaCpoOut = $cpoOut - $cpoAwal; // Cari CPO & PK yang memakai rupiah rata2 mutasi
$sisaPkOut = $pkOut - $pkAwal;
$qtyCpo1 = ($sisaCpoOut > 0)? $cpoAwal: $cpoOut; // Qty CPO & PK yang memakai harga awal
$qtyPk1 = ($sisaPkOut > 0)? $pkAwal: $pkOut;
$rpCpoOut = $qtyCpo1 * $cpoPriceAwal; // Rupiah dari CPO & PK yang memakai harga awal
$rpPkOut = $qtyPk1 * $pkPriceAwal;
if($sisaCpoOut > 0) $rpCpoOut += $sisaCpoOut * $cpoPriceMutasi;
if($sisaPkOut > 0) $rpPkOut += $sisaPkOut * $pkPriceMutasi;
//exit("error jam:".$sisaCpoOut."___".$cpoPriceMutasi."___".$rpCpoOut."___".$qtyCpo1."__".$cpoOut);
/**
* CPO & PK - Saldo Akhir
*/
$cpoQtyAkhir = $cpoAwal + $cpoIn - $cpoOut;
$cpoRpAkhir = $cpoRpAwal+($cpoRpOlah + $cpoRpInt + $cpoRpEks + $cpoRpAf+$cpoOverhead) - $rpCpoOut;
$pkQtyAkhir = $pkAwal + $pkIn - $pkOut;
$pkRpAkhir = $pkRpAwal+($pkRpOlah + $pkRpInt + $pkRpEks + $pkRpAf+$kerOverhead) - $rpPkOut;
/***************************************************************************
** Jurnal *****************************************************************
***************************************************************************/
// Init Param
$zJ = new zJournal();
$lastDay = cal_days_in_month(CAL_GREGORIAN,$bulan,$tahun);
$nojurnal = $tahunbulan.$lastDay.'/'.$unit.'/HPP/001';
$kodeJurnal = 'HPP';
$tanggalJurnal = $param['periode'].'-'.$lastDay;
$noUrut = 1;
$noRef = $kodeJurnal.'/'.$unit.'/'.$tahunbulan;
// Default Segment
$defSegment = colDefaultValue($dbname,'keu_5segment','kodesegment');
// Delete Jurnal
$qDel = deleteQuery($dbname,'keu_jurnalht',"nojurnal = '".$nojurnal."'");
if(!mysql_query($qDel)) exit("Delete Error: ".mysql_error());
// Prepare Data Header
$dataResHPP['header'] = array(
'nojurnal'=>$nojurnal, 'kodejurnal'=>$kodeJurnal,
'tanggal'=>$tanggalJurnal, 'tanggalentry'=>date('Ymd'),
'posting'=>'0',
'totaldebet'=>'0', 'totalkredit'=>'0',
'amountkoreksi'=>'0',
'noreferensi'=>$noRef,
'autojurnal'=>'1',
'matauang'=>'IDR', 'kurs'=>'1',
'revisi'=>'0'
);
// Prepare Data Detail
$dataResHPP['detail'] = array();
/***************************************************************************
** Jurnal TBS *************************************************************
***************************************************************************/
if($rpTbsInt > 0) {
// TBS Internal - Debet
$dataResHPP['detail'][] = array(
'nojurnal'=>$nojurnal, 'tanggal'=>$tanggalJurnal,
'nourut'=>$noUrut, 'noakun'=>'1150208',
'keterangan'=>'Produksi TBS Internal '.$ptUnit.' '.$param['periode'],
'jumlah'=>$rpTbsInt,
'matauang'=>'IDR', 'kurs'=>'1',
'kodeorg'=>$unit, 'kodekegiatan'=>'',
'kodeasset'=>'', 'kodebarang'=>$barang['tbs'],
'nik'=>'', 'kodecustomer'=>'', 'kodesupplier'=>'',
'noreferensi'=>$noRef, 'noaruskas'=>'',
'kodevhc'=>'', 'nodok'=>$noRef, 'kodeblok'=>'',
'revisi'=>'0', 'kodesegment' => $defSegment
);
$dataResHPP['header']['totaldebet'] += $rpTbsInt;
$dataResHPP['header']['totalkredit'] += $rpTbsInt;
$noUrut++;
// TBS Internal - Kredit
$dataResHPP['detail'][] = array(
'nojurnal'=>$nojurnal, 'tanggal'=>$tanggalJurnal,
'nourut'=>$noUrut, 'noakun'=>'6219999',
'keterangan'=>'Produksi TBS Internal '.$ptUnit.' '.$param['periode'],
'jumlah'=>$rpTbsInt * (-1),
'matauang'=>'IDR', 'kurs'=>'1',
'kodeorg'=>$unit, 'kodekegiatan'=>'',
'kodeasset'=>'', 'kodebarang'=>$barang['tbs'],
'nik'=>'', 'kodecustomer'=>'', 'kodesupplier'=>'',
'noreferensi'=>$noRef, 'noaruskas'=>'',
'kodevhc'=>'', 'nodok'=>$noRef, 'kodeblok'=>'',
'revisi'=>'0', 'kodesegment' => $defSegment
);
$noUrut++;
}
if(($rpTbsEks) > 0) {
// TBS Eksternal - Debet
$dataResHPP['detail'][] = array(
'nojurnal'=>$nojurnal, 'tanggal'=>$tanggalJurnal,
'nourut'=>$noUrut, 'noakun'=>'1150208',
'keterangan'=>'Pembelian TBS Eksternal '.$ptUnit.' '.$param['periode'],
'jumlah'=>$rpTbsEks,
'matauang'=>'IDR', 'kurs'=>'1',
'kodeorg'=>$unit, 'kodekegiatan'=>'',
'kodeasset'=>'', 'kodebarang'=>$barang['tbs'],
'nik'=>'', 'kodecustomer'=>'', 'kodesupplier'=>'',
'noreferensi'=>$noRef, 'noaruskas'=>'',
'kodevhc'=>'', 'nodok'=>$noRef, 'kodeblok'=>'',
'revisi'=>'0', 'kodesegment' => $defSegment
);
$noUrut++;
$dataResHPP['header']['totaldebet'] += $rpTbsEks;
$dataResHPP['header']['totalkredit'] += $rpTbsEks;
// TBS Eksternal - Kredit
$dataResHPP['detail'][] = array(
'nojurnal'=>$nojurnal, 'tanggal'=>$tanggalJurnal,
'nourut'=>$noUrut, 'noakun'=>'6430999',
'keterangan'=>'Pembelian TBS Eksternal '.$ptUnit.' '.$param['periode'],
'jumlah'=>$rpTbsEks * (-1),
'matauang'=>'IDR', 'kurs'=>'1',
'kodeorg'=>$unit, 'kodekegiatan'=>'',
'kodeasset'=>'', 'kodebarang'=>$barang['tbs'],
'nik'=>'', 'kodecustomer'=>'', 'kodesupplier'=>'',
'noreferensi'=>$noRef, 'noaruskas'=>'',
'kodevhc'=>'', 'nodok'=>$noRef, 'kodeblok'=>'',
'revisi'=>'0', 'kodesegment' => $defSegment
);
$noUrut++;
}
if(($rpTbsAf) > 0) {
// TBS Afiliasi - Debet
$dataResHPP['detail'][] = array(
'nojurnal'=>$nojurnal, 'tanggal'=>$tanggalJurnal,
'nourut'=>$noUrut, 'noakun'=>'1150208',
'keterangan'=>'Pembelian TBS Afiliasi '.$ptUnit.' '.$param['periode'],
'jumlah'=>$rpTbsAf,
'matauang'=>'IDR', 'kurs'=>'1',
'kodeorg'=>$unit, 'kodekegiatan'=>'',
'kodeasset'=>'', 'kodebarang'=>$barang['tbs'],
'nik'=>'', 'kodecustomer'=>'', 'kodesupplier'=>'',
'noreferensi'=>$noRef, 'noaruskas'=>'',
'kodevhc'=>'', 'nodok'=>$noRef, 'kodeblok'=>'',
'revisi'=>'0', 'kodesegment' => $defSegment
);
$noUrut++;
$dataResHPP['header']['totaldebet'] += $rpTbsAf;
$dataResHPP['header']['totalkredit'] += $rpTbsAf;
// TBS Afiliasi - Kredit
$dataResHPP['detail'][] = array(
'nojurnal'=>$nojurnal, 'tanggal'=>$tanggalJurnal,
'nourut'=>$noUrut, 'noakun'=>'6430999',
'keterangan'=>'Pembelian TBS Afiliasi '.$ptUnit.' '.$param['periode'],
'jumlah'=>$rpTbsAf * (-1),
'matauang'=>'IDR', 'kurs'=>'1',
'kodeorg'=>$unit, 'kodekegiatan'=>'',
'kodeasset'=>'', 'kodebarang'=>$barang['tbs'],
'nik'=>'', 'kodecustomer'=>'', 'kodesupplier'=>'',
'noreferensi'=>$noRef, 'noaruskas'=>'',
'kodevhc'=>'', 'nodok'=>$noRef, 'kodeblok'=>'',
'revisi'=>'0', 'kodesegment' => $defSegment
);
$noUrut++;
}
if($byOvHeadKbn>0){
// Overhead Kebun - Debet
$dataResHPP['detail'][] = array(
'nojurnal'=>$nojurnal, 'tanggal'=>$tanggalJurnal,
'nourut'=>$noUrut, 'noakun'=>'1150208',
'keterangan'=>'Biaya Overhead alokasi TBS '.$ptUnit.' '.$param['periode'],
'jumlah'=>$byOvHeadKbn,
'matauang'=>'IDR', 'kurs'=>'1',
'kodeorg'=>$unit, 'kodekegiatan'=>'',
'kodeasset'=>'', 'kodebarang'=>$barang['tbs'],
'nik'=>'', 'kodecustomer'=>'', 'kodesupplier'=>'',
'noreferensi'=>$noRef, 'noaruskas'=>'',
'kodevhc'=>'', 'nodok'=>$noRef, 'kodeblok'=>'',
'revisi'=>'0', 'kodesegment' => $defSegment
);
$noUrut++;
$dataResHPP['header']['totaldebet'] += $byOvHeadKbn;
$dataResHPP['header']['totalkredit'] += $byOvHeadKbn;
// Overhead Kebun - Kredit
$dataResHPP['detail'][] = array(
'nojurnal'=>$nojurnal, 'tanggal'=>$tanggalJurnal,
'nourut'=>$noUrut, 'noakun'=>'7199999',
'keterangan'=>'Biaya Overhead alokasi TBS '.$ptUnit.' '.$param['periode'],
'jumlah'=>$byOvHeadKbn * (-1),
'matauang'=>'IDR', 'kurs'=>'1',
'kodeorg'=>$unit, 'kodekegiatan'=>'',
'kodeasset'=>'', 'kodebarang'=>$barang['tbs'],
'nik'=>'', 'kodecustomer'=>'', 'kodesupplier'=>'',
'noreferensi'=>$noRef, 'noaruskas'=>'',
'kodevhc'=>'', 'nodok'=>$noRef, 'kodeblok'=>'',
'revisi'=>'0', 'kodesegment' => $defSegment
);
$noUrut++;
}
if($rpTbsOut > 0) {
// TBS Diolah - Debet
$dataResHPP['detail'][] = array(
'nojurnal'=>$nojurnal, 'tanggal'=>$tanggalJurnal,
'nourut'=>$noUrut, 'noakun'=>'6410500',
'keterangan'=>'Harga Pokok Penjualan TBS '.$ptUnit.' '.$param['periode'],
'jumlah'=>$rpTbsOut,
'matauang'=>'IDR', 'kurs'=>'1',
'kodeorg'=>$unit, 'kodekegiatan'=>'',
'kodeasset'=>'', 'kodebarang'=>$barang['tbs'],
'nik'=>'', 'kodecustomer'=>'', 'kodesupplier'=>'',
'noreferensi'=>$noRef, 'noaruskas'=>'',
'kodevhc'=>'', 'nodok'=>$noRef, 'kodeblok'=>'',
'revisi'=>'0', 'kodesegment' => $defSegment
);
$noUrut++;
$dataResHPP['header']['totaldebet'] += $rpTbsOut;
$dataResHPP['header']['totalkredit'] += $rpTbsOut;
// TBS Diolah - Kredit
$dataResHPP['detail'][] = array(
'nojurnal'=>$nojurnal, 'tanggal'=>$tanggalJurnal,
'nourut'=>$noUrut, 'noakun'=>'1150208',
'keterangan'=>'Harga Pokok Penjualan TBS '.$ptUnit.' '.$param['periode'],
'jumlah'=>$rpTbsOut * (-1),
'matauang'=>'IDR', 'kurs'=>'1',
'kodeorg'=>$unit, 'kodekegiatan'=>'',
'kodeasset'=>'', 'kodebarang'=>$barang['tbs'],
'nik'=>'', 'kodecustomer'=>'', 'kodesupplier'=>'',
'noreferensi'=>$noRef, 'noaruskas'=>'',
'kodevhc'=>'', 'nodok'=>$noRef, 'kodeblok'=>'',
'revisi'=>'0', 'kodesegment' => $defSegment
);
$noUrut++;
}
/***************************************************************************
** Jurnal CPO *************************************************************
***************************************************************************/
if($cpoRpOlah > 0) {
// CPO Olah - Debet
$dataResHPP['detail'][] = array(
'nojurnal'=>$nojurnal, 'tanggal'=>$tanggalJurnal,
'nourut'=>$noUrut, 'noakun'=>'1150201',
'keterangan'=>'Penerimaan TBS (CPO Olah) '.$ptUnit.' '.$param['periode'],
'jumlah'=>$cpoRpOlah,
'matauang'=>'IDR', 'kurs'=>'1',
'kodeorg'=>$unit, 'kodekegiatan'=>'',
'kodeasset'=>'', 'kodebarang'=>$barang['cpo'],
'nik'=>'', 'kodecustomer'=>'', 'kodesupplier'=>'',
'noreferensi'=>$noRef, 'noaruskas'=>'',
'kodevhc'=>'', 'nodok'=>$noRef, 'kodeblok'=>'',
'revisi'=>'0', 'kodesegment' => $defSegment
);
$noUrut++;
$dataResHPP['header']['totaldebet'] += $cpoRpOlah;
$dataResHPP['header']['totalkredit'] += $cpoRpOlah;
// CPO Olah - Kredit
$dataResHPP['detail'][] = array(
'nojurnal'=>$nojurnal, 'tanggal'=>$tanggalJurnal,
'nourut'=>$noUrut, 'noakun'=>'6410500',
'keterangan'=>'Penerimaan TBS (CPO Olah) '.$ptUnit.' '.$param['periode'],
'jumlah'=>$cpoRpOlah * (-1),
'matauang'=>'IDR', 'kurs'=>'1',
'kodeorg'=>$unit, 'kodekegiatan'=>'',
'kodeasset'=>'', 'kodebarang'=>$barang['cpo'],
'nik'=>'', 'kodecustomer'=>'', 'kodesupplier'=>'',
'noreferensi'=>$noRef, 'noaruskas'=>'',
'kodevhc'=>'', 'nodok'=>$noRef, 'kodeblok'=>'',
'revisi'=>'0', 'kodesegment' => $defSegment
);
$noUrut++;
}
if($cpoRpInt > 0) {
// Biaya Pabrik - Debet
$dataResHPP['detail'][] = array(
'nojurnal'=>$nojurnal, 'tanggal'=>$tanggalJurnal,
'nourut'=>$noUrut, 'noakun'=>'1150201',
'keterangan'=>'Biaya Pabrik porsi CPO '.$ptUnit.' '.$param['periode'],
'jumlah'=>$cpoRpInt,
'matauang'=>'IDR', 'kurs'=>'1',
'kodeorg'=>$unit, 'kodekegiatan'=>'',
'kodeasset'=>'', 'kodebarang'=>$barang['cpo'],
'nik'=>'', 'kodecustomer'=>'', 'kodesupplier'=>'',
'noreferensi'=>$noRef, 'noaruskas'=>'',
'kodevhc'=>'', 'nodok'=>$noRef, 'kodeblok'=>'',
'revisi'=>'0', 'kodesegment' => $defSegment
);
$noUrut++;
$dataResHPP['header']['totaldebet'] += $cpoRpInt;
$dataResHPP['header']['totalkredit'] += $cpoRpInt;
// Biaya Pabrik - Kredit
$dataResHPP['detail'][] = array(
'nojurnal'=>$nojurnal, 'tanggal'=>$tanggalJurnal,
'nourut'=>$noUrut, 'noakun'=>'6330100',
'keterangan'=>'Biaya Pabrik porsi CPO '.$ptUnit.' '.$param['periode'],
'jumlah'=>$cpoRpInt * (-1),
'matauang'=>'IDR', 'kurs'=>'1',
'kodeorg'=>$unit, 'kodekegiatan'=>'',
'kodeasset'=>'', 'kodebarang'=>$barang['cpo'],
'nik'=>'', 'kodecustomer'=>'', 'kodesupplier'=>'',
'noreferensi'=>$noRef, 'noaruskas'=>'',
'kodevhc'=>'', 'nodok'=>$noRef, 'kodeblok'=>'',
'revisi'=>'0', 'kodesegment' => $defSegment
);
$noUrut++;
}
if(($cpoRpEks) > 0) {
// CPO Eksternal - Debet
$dataResHPP['detail'][] = array(
'nojurnal'=>$nojurnal, 'tanggal'=>$tanggalJurnal,
'nourut'=>$noUrut, 'noakun'=>'1150201',
'keterangan'=>'Pembelian CPO Eksternal '.$ptUnit.' '.$param['periode'],
'jumlah'=>$cpoRpEks,
'matauang'=>'IDR', 'kurs'=>'1',
'kodeorg'=>$unit, 'kodekegiatan'=>'',
'kodeasset'=>'', 'kodebarang'=>$barang['cpo'],
'nik'=>'', 'kodecustomer'=>'', 'kodesupplier'=>'',
'noreferensi'=>$noRef, 'noaruskas'=>'',
'kodevhc'=>'', 'nodok'=>$noRef, 'kodeblok'=>'',
'revisi'=>'0', 'kodesegment' => $defSegment
);
$noUrut++;
$dataResHPP['header']['totaldebet'] += $cpoRpEks;
$dataResHPP['header']['totalkredit'] += $cpoRpEks;
// CPO Eksternal - Kredit
$dataResHPP['detail'][] = array(
'nojurnal'=>$nojurnal, 'tanggal'=>$tanggalJurnal,
'nourut'=>$noUrut, 'noakun'=>'6431999',
'keterangan'=>'Pembelian CPO Eksternal '.$ptUnit.' '.$param['periode'],
'jumlah'=>$cpoRpEks * (-1),
'matauang'=>'IDR', 'kurs'=>'1',
'kodeorg'=>$unit, 'kodekegiatan'=>'',
'kodeasset'=>'', 'kodebarang'=>$barang['cpo'],
'nik'=>'', 'kodecustomer'=>'', 'kodesupplier'=>'',
'noreferensi'=>$noRef, 'noaruskas'=>'',
'kodevhc'=>'', 'nodok'=>$noRef, 'kodeblok'=>'',
'revisi'=>'0', 'kodesegment' => $defSegment
);
$noUrut++;
}
if(($cpoRpAf) > 0) {
// CPO Afiliasi - Debet
$dataResHPP['detail'][] = array(
'nojurnal'=>$nojurnal, 'tanggal'=>$tanggalJurnal,
'nourut'=>$noUrut, 'noakun'=>'1150201',
'keterangan'=>'Pembelian CPO Afiliasi '.$ptUnit.' '.$param['periode'],
'jumlah'=>$cpoRpAf,
'matauang'=>'IDR', 'kurs'=>'1',
'kodeorg'=>$unit, 'kodekegiatan'=>'',
'kodeasset'=>'', 'kodebarang'=>$barang['cpo'],
'nik'=>'', 'kodecustomer'=>'', 'kodesupplier'=>'',
'noreferensi'=>$noRef, 'noaruskas'=>'',
'kodevhc'=>'', 'nodok'=>$noRef, 'kodeblok'=>'',
'revisi'=>'0', 'kodesegment' => $defSegment
);
$noUrut++;
$dataResHPP['header']['totaldebet'] += $cpoRpAf;
$dataResHPP['header']['totalkredit'] += $cpoRpAf;
// CPO Afiliasi - Kredit
$dataResHPP['detail'][] = array(
'nojurnal'=>$nojurnal, 'tanggal'=>$tanggalJurnal,
'nourut'=>$noUrut, 'noakun'=>'6431999',
'keterangan'=>'Pembelian CPO Afiliasi '.$ptUnit.' '.$param['periode'],
'jumlah'=>$cpoRpAf * (-1),
'matauang'=>'IDR', 'kurs'=>'1',
'kodeorg'=>$unit, 'kodekegiatan'=>'',
'kodeasset'=>'', 'kodebarang'=>$barang['cpo'],
'nik'=>'', 'kodecustomer'=>'', 'kodesupplier'=>'',
'noreferensi'=>$noRef, 'noaruskas'=>'',
'kodevhc'=>'', 'nodok'=>$noRef, 'kodeblok'=>'',
'revisi'=>'0', 'kodesegment' => $defSegment
);
$noUrut++;
}
if($cpoOverhead>0){
// Overhead CPO - Debet
$dataResHPP['detail'][] = array(
'nojurnal'=>$nojurnal, 'tanggal'=>$tanggalJurnal,
'nourut'=>$noUrut, 'noakun'=>'1150201',
'keterangan'=>'Biaya Overhead alokasi CPO '.$ptUnit.' '.$param['periode'],
'jumlah'=>$cpoOverhead,
'matauang'=>'IDR', 'kurs'=>'1',
'kodeorg'=>$unit, 'kodekegiatan'=>'',
'kodeasset'=>'', 'kodebarang'=>$barang['cpo'],
'nik'=>'', 'kodecustomer'=>'', 'kodesupplier'=>'',
'noreferensi'=>$noRef, 'noaruskas'=>'',
'kodevhc'=>'', 'nodok'=>$noRef, 'kodeblok'=>'',
'revisi'=>'0', 'kodesegment' => $defSegment
);
$noUrut++;
$dataResHPP['header']['totaldebet'] += $cpoOverhead;
$dataResHPP['header']['totalkredit'] += $cpoOverhead;
// Overhead CPO - Kredit
$dataResHPP['detail'][] = array(
'nojurnal'=>$nojurnal, 'tanggal'=>$tanggalJurnal,
'nourut'=>$noUrut, 'noakun'=>'7199999',
'keterangan'=>'Biaya Overhead alokasi CPO '.$ptUnit.' '.$param['periode'],
'jumlah'=>$cpoOverhead * (-1),
'matauang'=>'IDR', 'kurs'=>'1',
'kodeorg'=>$unit, 'kodekegiatan'=>'',
'kodeasset'=>'', 'kodebarang'=>$barang['cpo'],
'nik'=>'', 'kodecustomer'=>'', 'kodesupplier'=>'',
'noreferensi'=>$noRef, 'noaruskas'=>'',
'kodevhc'=>'', 'nodok'=>$noRef, 'kodeblok'=>'',
'revisi'=>'0', 'kodesegment' => $defSegment
);
$noUrut++;
}
if($rpCpoOut > 0) {
// CPO Dikirim - Debet
$dataResHPP['detail'][] = array(
'nojurnal'=>$nojurnal, 'tanggal'=>$tanggalJurnal,
'nourut'=>$noUrut, 'noakun'=>'6410600',
'keterangan'=>'Harga Pokok Penjualan CPO '.$ptUnit.' '.$param['periode'],
'jumlah'=>$rpCpoOut,
'matauang'=>'IDR', 'kurs'=>'1',
'kodeorg'=>$unit, 'kodekegiatan'=>'',
'kodeasset'=>'', 'kodebarang'=>$barang['cpo'],
'nik'=>'', 'kodecustomer'=>'', 'kodesupplier'=>'',
'noreferensi'=>$noRef, 'noaruskas'=>'',
'kodevhc'=>'', 'nodok'=>$noRef, 'kodeblok'=>'',
'revisi'=>'0', 'kodesegment' => $defSegment
);
$noUrut++;
$dataResHPP['header']['totaldebet'] += $rpCpoOut;
$dataResHPP['header']['totalkredit'] += $rpCpoOut;
// CPO Dikirim - Kredit
$dataResHPP['detail'][] = array(
'nojurnal'=>$nojurnal, 'tanggal'=>$tanggalJurnal,
'nourut'=>$noUrut, 'noakun'=>'1150201',
'keterangan'=>'Harga Pokok Penjualan CPO '.$ptUnit.' '.$param['periode'],
'jumlah'=>$rpCpoOut * (-1),
'matauang'=>'IDR', 'kurs'=>'1',
'kodeorg'=>$unit, 'kodekegiatan'=>'',
'kodeasset'=>'', 'kodebarang'=>$barang['cpo'],
'nik'=>'', 'kodecustomer'=>'', 'kodesupplier'=>'',
'noreferensi'=>$noRef, 'noaruskas'=>'',
'kodevhc'=>'', 'nodok'=>$noRef, 'kodeblok'=>'',
'revisi'=>'0', 'kodesegment' => $defSegment
);
$noUrut++;
}
/***************************************************************************
** Jurnal PK (Kernel) *****************************************************
***************************************************************************/
if($pkRpOlah > 0) {
// PK Olah - Debet
$dataResHPP['detail'][] = array(
'nojurnal'=>$nojurnal, 'tanggal'=>$tanggalJurnal,
'nourut'=>$noUrut, 'noakun'=>'1150202',
'keterangan'=>'Penerimaan TBS (PK Olah) '.$ptUnit.' '.$param['periode'],
'jumlah'=>$pkRpOlah,
'matauang'=>'IDR', 'kurs'=>'1',
'kodeorg'=>$unit, 'kodekegiatan'=>'',
'kodeasset'=>'', 'kodebarang'=>$barang['pk'],
'nik'=>'', 'kodecustomer'=>'', 'kodesupplier'=>'',