<commit_before>var global = require('../../global');

module.exports = function (data, offset) {

    var items = data.items.map(invoiceNote => {
        var invoiceItem = invoiceNote.items.map(dataItem => {
            var _items = dataItem.items.map(item => {
                dueDate = new Date(dataItem.deliveryOrderSupplierDoDate);
                dueDate.setDate(dueDate.getDate() + item.paymentDueDays);
                return {
                    deliveryOrderNo: dataItem.deliveryOrderNo,
                    date: dataItem.deliveryOrderDate,
                    purchaseRequestRefNo: item.purchaseRequestRefNo,
                    product: item.product.name,
                    productDesc: item.product.description,
                    quantity: item.deliveredQuantity,
                    uom: item.purchaseOrderUom.unit,
                    unit: item.unit,
                    price: item.pricePerDealUnit,
                    priceTotal: item.pricePerDealUnit * item.deliveredQuantity,
                    correction: item.correction,
                    dueDate: dueDate,
                    paymentMethod: item.paymentMethod,
                    currRate: item.kursRate,
                }
            });
            _items = [].concat.apply([], _items);
            return _items;
        })
        invoiceItem = [].concat.apply([], invoiceItem);
        return invoiceItem;
    });
    items = [].concat.apply([], items);

    var dueDate, paymentMethod;

    var dueDates = items.map(item => {
        return item.dueDate
    })
    dueDate = Math.max.apply(null, dueDates);
    paymentMethod = items[0].paymentMethod;

    var useIncomeTax = data.items
        .map((item) => item.useIncomeTax)
        .reduce((prev, curr, index) => {
            return prev && curr
        }, true);

    var useVat = data.items
        .map((item) => item.useVat)
        .reduce((prev, curr, index) => {
            return prev && curr
        }, true);

    var vatRate = 0;
    if (useVat) {
        vatRate = data.items[0].vat.rate;
    }

    var sumByUnit = [];
    items.reduce(function (res, value) {
        if (!res[value.unit]) {
            res[value.unit] = {
                priceTotal: 0,
                unit: value.unit
            };
            sumByUnit.push(res[value.unit])
        }
        res[value.unit].priceTotal += value.priceTotal
        return res;
    }, {});

    var locale = global.config.locale;
    var moment = require('moment');
    moment.locale(locale.name);

    var header = [
        {
            stack: [
                'PT. DAN LIRIS',
                'Head Office   : ',
                '<NAME>, Kecamatan Grogol',
                'Sukoharjo 57193 - INDONESIA',
                'PO.BOX 166 Solo 57100',
                'Telp. (0271) 740888, 714400',
                'Fax. (0271) 735222, 740777'
            ],
            alignment: "left",
            style: ['size06', 'bold']
        },
        {
            alignment: "center",
            text: 'NOTA INTERN',
            style: ['size08', 'bold']
        },
        '\n'
    ];

    var subHeader = [
        {
            columns: [
                {
                    width: '50%',
                    stack: [
                        {
                            columns: [{
                                width: '25%',
                                text: 'No. Nota Intern',
                                style: ['size06']
                            }, {
                                width: '2%',
                                text: ':',
                                style: ['size06']
                            }, {
                                width: '*',
                                text: data.no,
                                style: ['size06']
                            }]
                        },
                        {
                            columns: [{
                                width: '25%',
                                text: 'Kode Supplier',
                                style: ['size06']
                            }, {
                                width: '2%',
                                text: ':',
                                style: ['size06']
                            }, {
                                width: '*',
                                text: data.supplier.code,
                                style: ['size06']
                            }]
                        },
                        {
                            columns: [{
                                width: '25%',
                                text: 'Nama Supplier',
                                style: ['size06']
                            }, {
                                width: '2%',
                                text: ':',
                                style: ['size06']
                            }, {
                                width: '*',
                                text: data.supplier.name,
                                style: ['size06']
                            }]
                        }
                    ]
                }, {
                    width: '50%',
                    stack: [
                        {
                            columns: [{
                                width: '25%',
                                text: 'Tgl. Nota Intern',
                                style: ['size06']
                            }, {
                                width: '2%',
                                text: ':',
                                style: ['size06']
                            }, {
                                width: '*',
                                text: `${moment(data.date).add(offset, 'h').format("DD MMM YYYY")}`,
                                style: ['size06']
                            }]
                        },
                        {
                            columns: [{
                                width: '25%',
                                text: 'Tgl. Jatuh Tempo',
                                style: ['size06']
                            }, {
                                width: '2%',
                                text: ':',
                                style: ['size06']
                            }, {
                                width: '*',
                                text: `${moment(dueDate).add(offset, 'h').format("DD MMM YYYY")}`,
                                style: ['size06']
                            }]
                        }
                    ]
                }
            ]
        },
        {
            text: '\n',
            style: ['size06']
        }
    ];

    var thead = [
        {
            text: 'No. Surat Jalan',
            style: ['size06', 'bold', 'center']
        }, {
            text: 'Tgl. Surat Jalan',<commit_msg>add Term Pembayaran<commit_after>var global = require('../../global');

module.exports = function (data, offset) {

    var items = data.items.map(invoiceNote => {
        var invoiceItem = invoiceNote.items.map(dataItem => {
            var _items = dataItem.items.map(item => {
                dueDate = new Date(dataItem.deliveryOrderSupplierDoDate);
                dueDate.setDate(dueDate.getDate() + item.paymentDueDays);
                return {
                    deliveryOrderNo: dataItem.deliveryOrderNo,
                    date: dataItem.deliveryOrderDate,
                    purchaseRequestRefNo: item.purchaseRequestRefNo,
                    product: item.product.name,
                    productDesc: item.product.description,
                    quantity: item.deliveredQuantity,
                    uom: item.purchaseOrderUom.unit,
                    unit: item.unit,
                    price: item.pricePerDealUnit,
                    priceTotal: item.pricePerDealUnit * item.deliveredQuantity,
                    correction: item.correction,
                    dueDate: dueDate,
                    paymentMethod: item.paymentMethod,
                    currRate: item.kursRate,
                }
            });
            _items = [].concat.apply([], _items);
            return _items;
        })
        invoiceItem = [].concat.apply([], invoiceItem);
        return invoiceItem;
    });
    items = [].concat.apply([], items);

    var dueDate, paymentMethod;

    var dueDates = items.map(item => {
        return item.dueDate
    })
    dueDate = Math.max.apply(null, dueDates);
    paymentMethod = items[0].paymentMethod;

    var useIncomeTax = data.items
        .map((item) => item.useIncomeTax)
        .reduce((prev, curr, index) => {
            return prev && curr
        }, true);

    var useVat = data.items
        .map((item) => item.useVat)
        .reduce((prev, curr, index) => {
            return prev && curr
        }, true);

    var vatRate = 0;
    if (useVat) {
        vatRate = data.items[0].vat.rate;
    }

    var sumByUnit = [];
    items.reduce(function (res, value) {
        if (!res[value.unit]) {
            res[value.unit] = {
                priceTotal: 0,
                unit: value.unit
            };
            sumByUnit.push(res[value.unit])
        }
        res[value.unit].priceTotal += value.priceTotal
        return res;
    }, {});

    var locale = global.config.locale;
    var moment = require('moment');
    moment.locale(locale.name);

    var header = [
        {
            stack: [
                'PT. DAN LIRIS',
                'Head Office   : ',
                'Kelurahan Banaran, Kecamatan Grogol',
                'Sukoharjo 57193 - INDONESIA',
                'PO.BOX 166 Solo 57100',
                'Telp. (0271) 740888, 714400',
                'Fax. (0271) 735222, 740777'
            ],
            alignment: "left",
            style: ['size06', 'bold']
        },
        {
            alignment: "center",
            text: 'NOTA INTERN',
            style: ['size08', 'bold']
        },
        '\n'
    ];

    var subHeader = [
        {
            columns: [
                {
                    width: '50%',
                    stack: [
                        {
                            columns: [{
                                width: '25%',
                                text: 'No. Nota Intern',
                                style: ['size06']
                            }, {
                                width: '2%',
                                text: ':',
                                style: ['size06']
                            }, {
                                width: '*',
                                text: data.no,
                                style: ['size06']
                            }]
                        },
                        {
                            columns: [{
                                width: '25%',
                                text: 'Kode Supplier',
                                style: ['size06']
                            }, {
                                width: '2%',
                                text: ':',
                                style: ['size06']
                            }, {
                                width: '*',
                                text: data.supplier.code,
                                style: ['size06']
                            }]
                        },
                        {
                            columns: [{
                                width: '25%',
                                text: 'Nama Supplier',
                                style: ['size06']
                            }, {
                                width: '2%',
                                text: ':',
                                style: ['size06']
                            }, {
                                width: '*',
                                text: data.supplier.name,
                                style: ['size06']
                            }]
                        }
                    ]
                }, {
                    width: '50%',
                    stack: [
                        {
                            columns: [{
                                width: '25%',
                                text: 'Tgl. Nota Intern',
                                style: ['size06']
                            }, {
                                width: '2%',
                                text: ':',
                                style: ['size06']
                            }, {
                                width: '*',
                                text: `${moment(data.date).add(offset, 'h').format("DD MMM YYYY")}`,
                                style: ['size06']
                            }]
                        },
                        {
                            columns: [{
                                width: '25%',
                                text: 'Tgl. Jatuh Tempo',
                                style: ['size06']
                            }, {
                                width: '2%',
                                text: ':',
                                style: ['size06']
                            }, {
                                width: '*',
                                text: `${moment(dueDate).add(offset, 'h').format("DD MMM YYYY")}`,
                                style: ['size06']
                            }]
                        },{
                            columns: [{
                                width: '25%',
                                text: 'Term Pembayaran',
                                style: ['size06']
                            }, {
                                width: '2%',
                                text: ':',
                                style: ['size06']
                            }, {
                                width: '*',
                                text: paymentMethod,
                                style: ['size06']
                            }]
                        },
                    ]
                }
            ]
        },
        {
            text: '\n',
            style: ['size06']
        }
    ];

    var thead = [
        {
            text: 'No. Surat Jalan',
            style: ['size06', 'bold', 'center']
        }, {
            text: 'Tgl. Surat Jalan',
{'fraction_non_alphanumeric': 0.1099312929419113, 'fraction_numerical': 0.015337636199597474, 'mean_word_length': 0.6931030431206674, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4928172', 'n_tokens_mistral': 3667, 'n_tokens_neox': 3281, 'n_words': 616}