feat: enhance CuttingItemSubRow to display total material usage and results by raw material
This commit is contained in:
parent
659104fa19
commit
3ef948c47f
@ -1,4 +1,3 @@
|
|||||||
import { ChevronDown, Pencil, Trash2 } from 'lucide-react';
|
|
||||||
import { ImagePreviewButton } from '@/components/image-preview-button';
|
import { ImagePreviewButton } from '@/components/image-preview-button';
|
||||||
import { RowActions } from '@/components/row-actions';
|
import { RowActions } from '@/components/row-actions';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
@ -6,6 +5,7 @@ import { Card, CardContent } from '@/components/ui/card';
|
|||||||
import { useCan } from '@/hooks/use-can';
|
import { useCan } from '@/hooks/use-can';
|
||||||
import { formatDateTime, formatNumber } from '@/lib/format';
|
import { formatDateTime, formatNumber } from '@/lib/format';
|
||||||
import { formatCurrency } from '@/lib/utils';
|
import { formatCurrency } from '@/lib/utils';
|
||||||
|
import { ChevronDown, Pencil, Trash2 } from 'lucide-react';
|
||||||
import type { Cutting } from './columns';
|
import type { Cutting } from './columns';
|
||||||
|
|
||||||
export type CuttingCardRowParams = {
|
export type CuttingCardRowParams = {
|
||||||
@ -118,6 +118,14 @@ export function CuttingCardRow({
|
|||||||
{formatCurrency(cutting.cost_per_unit)}
|
{formatCurrency(cutting.cost_per_unit)}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
|
{cutting.total_material_cost && (
|
||||||
|
<span className="font-semibold">
|
||||||
|
<span className="font-normal text-muted-foreground">
|
||||||
|
Biaya Keseluruhan:{' '}
|
||||||
|
</span>
|
||||||
|
{formatCurrency(cutting.total_material_cost)}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{cutting.photo_url && (
|
{cutting.photo_url && (
|
||||||
|
|||||||
@ -69,16 +69,41 @@ export function CuttingItemSubRow({ cutting }: { cutting: Cutting }) {
|
|||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
{Object.entries(singleByRawMaterial).map(
|
{Object.entries(singleByRawMaterial).map(
|
||||||
([rawMaterialName, groupItems]) => (
|
([rawMaterialName, groupItems]) => {
|
||||||
<Fragment key={rawMaterialName}>
|
const totalPemakaian = groupItems.reduce(
|
||||||
<TableRow>
|
(sum, item) =>
|
||||||
<TableCell
|
sum + Number(item.material_usage),
|
||||||
colSpan={5}
|
0,
|
||||||
className="text-center font-medium text-muted-foreground bg-muted/20"
|
);
|
||||||
>
|
const totalHasil = groupItems.reduce(
|
||||||
{rawMaterialName}
|
(sum, item) =>
|
||||||
</TableCell>
|
sum +
|
||||||
</TableRow>
|
(item.material_result !== null
|
||||||
|
? Number(item.material_result)
|
||||||
|
: 0),
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Fragment key={rawMaterialName}>
|
||||||
|
<TableRow>
|
||||||
|
<TableCell
|
||||||
|
colSpan={3}
|
||||||
|
className="text-center font-medium text-muted-foreground bg-muted/20"
|
||||||
|
>
|
||||||
|
{rawMaterialName}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="text-right font-medium text-muted-foreground bg-muted/20">
|
||||||
|
{formatNumber(
|
||||||
|
totalPemakaian,
|
||||||
|
)}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="text-right font-medium text-muted-foreground bg-muted/20">
|
||||||
|
{formatNumber(
|
||||||
|
totalHasil,
|
||||||
|
)}
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
{groupItems.map((item) => {
|
{groupItems.map((item) => {
|
||||||
counter++;
|
counter++;
|
||||||
return (
|
return (
|
||||||
@ -128,8 +153,9 @@ export function CuttingItemSubRow({ cutting }: { cutting: Cutting }) {
|
|||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</Fragment>
|
</Fragment>
|
||||||
),
|
);
|
||||||
)}
|
},
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user