Skip to content

Commit

Permalink
Merge pull request #20 from imkarimkarim/print-sum-cars
Browse files Browse the repository at this point in the history
  • Loading branch information
imkarimkarim authored Oct 4, 2022
2 parents ba733be + f65e8ba commit c5c4725
Show file tree
Hide file tree
Showing 11 changed files with 507 additions and 15 deletions.
13 changes: 11 additions & 2 deletions DOCS/DOCS.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
# DOCS

<i> ⚠️ dev docs is still under development... </i>
<i> ⚠️ dev docs is still in beta... </i>

## core concept

app has few main concepts:
product, factor, customer, productOwner, car
checkout the relationship between this entities [here](concept.png)

## how to works
## data transfer system

component -> ipcRendered -> db(docs)
component <- ipcRendered <- db(docs)

...


## electron

for now goje relying on old version of packages(like electron 11)
but it will upgrade to new versions soon...
16 changes: 15 additions & 1 deletion src/App/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import SearchProductOwners from "./Pages/Reports/SearchProductOwners.jsx";
import { createMemoryHistory } from "history";
import { hot } from "react-hot-loader";
import PayTheCashPlease from "./Components/PayTheCashPlease.jsx";
import SearchProductOwnerCars from "./Pages/Reports/SearchProductOwnerCars.jsx";
import PrintSumProductOwnerSelectedCars from "./Pages/Reports/PrintSumProductOwnerSelectedCars.jsx";
const JDate = require("jalali-date");

const App = () => {
Expand All @@ -55,7 +57,11 @@ const App = () => {
isCashDate ? (
<Redirect to="/payTheCashPlease" />
) : (
<Redirect to="/welcome" />
// <Redirect
// // to={`/printSumProductOwnerSelectedCars/آقای بهشاد قنبرزاده 12/${ids}`}
// />
// <Redirect to="/welcome" />
<Redirect to="/searchProductOwners" />
)
) : (
<div></div>
Expand Down Expand Up @@ -95,6 +101,14 @@ const App = () => {
path="/printRemainingProducts"
component={PrintRemainingProducts}
/>
<Route
path="/searchProductOwnerCars/:id"
component={SearchProductOwnerCars}
/>
<Route
path="/printSumProductOwnerSelectedCars/:ownerName/:selectedCars"
component={PrintSumProductOwnerSelectedCars}
/>
<Route path="/payTheCashPlease" component={PayTheCashPlease} />
</NotifProvider>
</PathStackProvider>
Expand Down
32 changes: 32 additions & 0 deletions src/App/Components/Report/CustomeDatePicker.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from "react";
import { cleanTime, oneDay } from "../../utils";
import { DatePicker } from "jalali-react-datepicker";

export default function CustomeDatePicker({ search, setSearch }) {
return (
<div className="searchbox-datePicker">
از تاریخ:
<DatePicker
timePicker={false}
value={search.fromm}
onClickSubmitButton={({ value }) => {
setSearch({
...search,
fromm: cleanTime(value._d.getTime()),
});
}}
/>
تا تاریخ:
<DatePicker
timePicker={false}
value={search.till}
onClickSubmitButton={({ value }) => {
setSearch({
...search,
till: cleanTime(value._d.getTime()) + oneDay,
});
}}
/>
</div>
);
}
10 changes: 9 additions & 1 deletion src/App/Pages/Car/Car.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ function InfoSection({ car }) {
<span>صورتحساب</span>
<span> </span>
<span>
<h3>{car.owner}</h3>
<h3>
<Link to={"/searchProductOwnerCars/" + car.ownerId}>
{car.owner}
</Link>
</h3>
</span>
</p>
<Grid container spacing={3}>
Expand Down Expand Up @@ -89,9 +93,12 @@ function SaleSection({ products, car }) {
for (let i = 0; i < products.length; i++) {
fullSum += salesInfos[i].FULL_SALE;
}
// 0.01 for getting % (shortcut of Proportionality)
sumSaleCommission = Math.floor(fullSum * (car.commission * 0.01));
}

// TODO: cleanCode(move all this stuff to a ipc)
// TODO: move all the logic to ipc
useEffect(() => {
if (salesInfos && salesInfos.length !== products.length) {
getOneProductCalcs(products[salesInfos.length].customeId);
Expand Down Expand Up @@ -275,6 +282,7 @@ function SaleSection({ products, car }) {
0 ? (
<span>
<Expense
to={"/searchProductOwners"}
num={
fullSum -
(sumSaleCommission + car.portage + car.unload + car.cash)
Expand Down
151 changes: 151 additions & 0 deletions src/App/Pages/Reports/PrintSumProductOwnerSelectedCars.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
const { ipcRenderer } = require("electron");
import React, { useRef, useEffect, useContext } from "react";
import { Redirect, useParams } from "react-router-dom";
import Header from "../../Components/Header.jsx";
import Footer from "../../Components/Footer.jsx";
import { NotifContext } from "../../Contexts/NotifContext.jsx";
import Expense from "../../Components/Expense.jsx";
import { Grid } from "@material-ui/core";
import html2pdf from "html2pdf.js";
import JDate from "jalali-date";
import { useState } from "react";
import Loading from "../../Components/Loading.jsx";
import ShowDate from "../../Components/ShowDate.jsx";

function SaleSection({ cars, ownerName }) {
const [goBack, setGoBack] = useState(false);

let fullSum = 0;
for (let car of cars) {
fullSum += car.ownerEarnings;
}

useEffect(() => {
if (!goBack) {
const jdate = new JDate();
const fileName = `صورتحساب های ${ownerName} - ${jdate.format(
"DD MMMM YYYY"
)}.pdf`;
const options = {
jsPDF: { format: "a5" },
filename: fileName,
html2canvas: { scale: 1 },
};
html2pdf()
.set(options)
.from(document.body)
.save()
.then(() => {
setGoBack(true);
});
}
});

return (
<div>
{goBack ? (
<Redirect to="/welcome" />
) : (
<div className="sale">
<Grid container spacing={1}>
<Grid className="saleInfo-table" item xs={9}>
<table>
<thead>
<tr>
<th>تاریخ ورود</th>
<th>پلاک</th>
<th>کد ماشین</th>
<th>صافی</th>
</tr>
</thead>
<tbody>
{cars.map((car, index) => {
return (
<tr key={index}>
<td>{<ShowDate timestamp={car.arrivalDate} />}</td>
<td>{car.plaque}</td>
<td>{car.customeId}</td>
<td>{<Expense num={car.ownerEarnings} />}</td>
</tr>
);
})}
</tbody>
</table>
</Grid>
</Grid>
<div className="owner-earning-car">
<h3>
<span>مجموع صافی ها</span>
<span> :</span>
<span>
<Expense num={fullSum} />
</span>
</h3>
</div>
</div>
)}
</div>
);
}

export default function PrintSumProductOwnerSelectedCars() {
const { clearNotifs } = useContext(NotifContext);
let { ownerName, selectedCars } = useParams();
selectedCars = selectedCars.split(",");
const init = useRef(true);

const [cars, setCars] = useState();

const sumProductOwnerSelectedCars = (carIds) => {
ipcRenderer.send("sumProductOwnerSelectedCars", carIds);
};

useEffect(() => {
if (init.current) {
clearNotifs();
sumProductOwnerSelectedCars(selectedCars);
init.current = false;
}

ipcRenderer.on("sumProductOwnerSelectedCars", (event, cars) => {
setCars(cars.reverse());
});

// clean up
return () => {
ipcRenderer.removeAllListeners("sumProductOwnerSelectedCars");
};
});
const currentDate = new Date(new JDate()._d).getTime();

return cars && cars.length >= 2 ? (
<div>
<div className="printCar">
<Header />

<div className="info">
<p className="safiTitle">
<span>صورتحساب</span>
<span> </span>
<span>
<h3>{ownerName}</h3>
</span>
</p>
</div>
<div>
<span>تاریخ گزارش</span>
<span> :</span>
<span>
<ShowDate timestamp={currentDate} />
</span>
</div>

<br />
<SaleSection cars={cars} ownerName={ownerName} />
<Footer />
</div>
</div>
) : (
<Loading />
);
}
Loading

0 comments on commit c5c4725

Please sign in to comment.