2
0
mirror of https://github.com/frappe/books.git synced 2024-11-08 23:00:56 +00:00

incr: get printview to display

- printing still not working
This commit is contained in:
18alantom 2022-05-02 16:26:47 +05:30
parent 8cc46c584c
commit 8c19f51814
9 changed files with 53 additions and 30 deletions

View File

@ -18,7 +18,7 @@ import registerProcessListeners from './main/registerProcessListeners';
import { IPC_CHANNELS } from './utils/messages'; import { IPC_CHANNELS } from './utils/messages';
const WIDTH = 1200; const WIDTH = 1200;
const HEIGHT = 907; const HEIGHT = 900;
export class Main { export class Main {
title: string = 'Frappe Books'; title: string = 'Frappe Books';

View File

@ -110,7 +110,7 @@ export class Party extends Doc {
static getListViewSettings(): ListViewSettings { static getListViewSettings(): ListViewSettings {
return { return {
columns: ['name', 'phone', 'outstandingAmount'], columns: ['name', 'email', 'phone', 'outstandingAmount'],
}; };
} }

View File

@ -2,13 +2,13 @@
import { fyo } from 'src/initFyo'; import { fyo } from 'src/initFyo';
export default { export default {
name: 'Base', name: 'Base',
props: ['doc', 'printSettings'], props: { doc: Object, printSettings: Object },
data: () => ({ party: null, companyAddress: null }), data: () => ({ party: null, companyAddress: null }),
methods: { methods: {
format(row, fieldname) { format(row, fieldname) {
let value = row.get(fieldname); const value = row.get(fieldname);
return fyo.format(value, row.meta.getField(fieldname)); return fyo.format(value, fyo.getField(row.schemaName, fieldname));
} },
}, },
async mounted() { async mounted() {
await this.doc.loadLink('party'); await this.doc.loadLink('party');
@ -19,7 +19,7 @@ export default {
computed: { computed: {
isSalesInvoice() { isSalesInvoice() {
return this.doc.schemaName === 'SalesInvoice'; return this.doc.schemaName === 'SalesInvoice';
} },
} },
}; };
</script> </script>

View File

@ -23,7 +23,12 @@
</div> </div>
<div class="w-1/3"> <div class="w-1/3">
<div v-if="companyAddress">{{ companyAddress.addressDisplay }}</div> <div v-if="companyAddress">{{ companyAddress.addressDisplay }}</div>
<div v-if="fyo.singles.AccountingSettings && fyo.singles.AccountingSettings.gstin"> <div
v-if="
fyo.singles.AccountingSettings &&
fyo.singles.AccountingSettings.gstin
"
>
GSTIN: {{ fyo.singles.AccountingSettings.gstin }} GSTIN: {{ fyo.singles.AccountingSettings.gstin }}
</div> </div>
</div> </div>
@ -85,11 +90,7 @@
</div> </div>
<div class="px-6 mt-2 flex justify-end text-base"> <div class="px-6 mt-2 flex justify-end text-base">
<div class="w-1/2 bg-pink"> <div class="w-1/2 bg-pink">
<div <div class="text-sm tracking-widest text-gray-600 mt-2">Notes</div>
class="text-sm tracking-widest text-gray-600 mt-2"
>
Notes
</div>
<div class="my-4 text-lg whitespace-pre-line"> <div class="my-4 text-lg whitespace-pre-line">
{{ doc.terms }} {{ doc.terms }}
</div> </div>
@ -108,7 +109,16 @@
<div>{{ fyo.format(tax.amount, 'Currency') }}</div> <div>{{ fyo.format(tax.amount, 'Currency') }}</div>
</div> </div>
<div <div
class="flex pl-2 justify-between py-3 border-t text-green-600 font-semibold text-base" class="
flex
pl-2
justify-between
py-3
border-t
text-green-600
font-semibold
text-base
"
> >
<div>{{ t`Grand Total` }}</div> <div>{{ t`Grand Total` }}</div>
<div>{{ fyo.format(doc.grandTotal, 'Currency') }}</div> <div>{{ fyo.format(doc.grandTotal, 'Currency') }}</div>
@ -119,11 +129,11 @@
</template> </template>
<script> <script>
import Base from './Base'; import Base from './BaseTemplate.vue';
export default { export default {
name: 'Default', name: 'Default',
extends: Base, extends: Base,
props: ['doc', 'printSettings'] props: ['doc', 'printSettings'],
}; };
</script> </script>

View File

@ -128,7 +128,7 @@
</template> </template>
<script> <script>
import Base from './Base'; import Base from './BaseTemplate.vue';
export default { export default {
name: 'Business', name: 'Business',

View File

@ -140,7 +140,7 @@
</template> </template>
<script> <script>
import Base from './Base'; import Base from './BaseTemplate.vue';
export default { export default {
name: 'Minimal', name: 'Minimal',

View File

@ -101,7 +101,13 @@ export default {
} }
return columns return columns
.map((fieldname) => fyo.getField(this.schemaName, fieldname)) .map((fieldname) => {
if (typeof fieldname === 'object') {
return fieldname;
}
return fyo.getField(this.schemaName, fieldname);
})
.filter(Boolean); .filter(Boolean);
}, },
hasImage() { hasImage() {

View File

@ -12,6 +12,8 @@
{{ t`Save as PDF` }} {{ t`Save as PDF` }}
</Button> </Button>
</PageHeader> </PageHeader>
<!-- Printview Preview -->
<div <div
v-if="doc && printSettings" v-if="doc && printSettings"
class="flex justify-center flex-1 -mt-36 overflow-auto relative" class="flex justify-center flex-1 -mt-36 overflow-auto relative"
@ -34,6 +36,8 @@
</div> </div>
</div> </div>
</div> </div>
<!-- Printview Customizer -->
<div class="border-l w-80" v-if="showCustomiser"> <div class="border-l w-80" v-if="showCustomiser">
<div class="mt-4 px-4 flex items-center justify-between"> <div class="mt-4 px-4 flex items-center justify-between">
<h2 class="font-semibold">{{ t`Customise` }}</h2> <h2 class="font-semibold">{{ t`Customise` }}</h2>
@ -52,7 +56,7 @@ import Button from 'src/components/Button.vue';
import PageHeader from 'src/components/PageHeader.vue'; import PageHeader from 'src/components/PageHeader.vue';
import InvoiceTemplate from 'src/components/SalesInvoice/InvoiceTemplate.vue'; import InvoiceTemplate from 'src/components/SalesInvoice/InvoiceTemplate.vue';
import TwoColumnForm from 'src/components/TwoColumnForm.vue'; import TwoColumnForm from 'src/components/TwoColumnForm.vue';
import { makePDF } from 'src/utils'; import { makePDF } from 'src/utils/ipcCalls';
import { IPC_ACTIONS } from 'utils/messages'; import { IPC_ACTIONS } from 'utils/messages';
export default { export default {
@ -76,7 +80,7 @@ export default {
}, },
computed: { computed: {
printTemplate() { printTemplate() {
return InvoiceTemplate return InvoiceTemplate;
}, },
}, },
methods: { methods: {
@ -86,7 +90,7 @@ export default {
const html = this.$refs.printContainer.innerHTML; const html = this.$refs.printContainer.innerHTML;
fyo.telemetry.log(Verb.Exported, 'SalesInvoice', { extension: 'pdf' }); fyo.telemetry.log(Verb.Exported, 'SalesInvoice', { extension: 'pdf' });
makePDF(html, savePath); await makePDF(html, savePath);
}, },
async getSavePath() { async getSavePath() {
const options = { const options = {

View File

@ -10,7 +10,10 @@ const PRINT_OPTIONS = {
printSelectionOnly: false, printSelectionOnly: false,
}; };
export default async function makePDF(html, savePath) { export default async function saveHtmlAsPdf(
html: string,
savePath: string
): Promise<void> {
const printWindow = getInitializedPrintWindow(); const printWindow = getInitializedPrintWindow();
printWindow.webContents.executeJavaScript(` printWindow.webContents.executeJavaScript(`
@ -22,9 +25,7 @@ export default async function makePDF(html, savePath) {
await sleep(1); // Required else pdf'll be blank. await sleep(1); // Required else pdf'll be blank.
const data = await printWindow.webContents.printToPDF(PRINT_OPTIONS); const data = await printWindow.webContents.printToPDF(PRINT_OPTIONS);
await fs.writeFile(savePath, data, (error) => { await fs.writeFile(savePath, data);
if (error) throw error;
});
resolve(); resolve();
}); });
@ -38,15 +39,17 @@ function getInitializedPrintWindow() {
show: false, show: false,
webPreferences: { webPreferences: {
contextIsolation: false, contextIsolation: false,
nodeIntegration: process.env.ELECTRON_NODE_INTEGRATION, nodeIntegration: false,
}, },
}); });
printWindow.loadURL(getPrintWindowUrl()); const printWindowUrl = getPrintWindowUrl();
printWindow.loadURL(printWindowUrl);
return printWindow; return printWindow;
} }
function getPrintWindowUrl() { function getPrintWindowUrl() {
let url = global.WEBPACK_DEV_SERVER_URL; // @ts-ignore
let url = global.WEBPACK_DEV_SERVER_URL as string | undefined;
if (url) { if (url) {
url = url + 'print'; url = url + 'print';
} else { } else {